blob: 4f6eef66d695b5104508d43260deedccbc728a28 [file] [log] [blame]
rdevlin.cronin5e510e802016-07-26 15:09:201// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/extension_browsertest.h"
6#include "chrome/browser/extensions/extension_service.h"
7#include "chrome/browser/ui/tabs/tab_strip_model.h"
8#include "chrome/test/base/ui_test_utils.h"
9#include "content/public/test/browser_test_utils.h"
10
11namespace extensions {
12
13// Test that opening a window with an extension recorded as active, then
14// unloading the extension, all before the renderer is fully initialized,
15// doesn't crash. This addresses crbug.com/528026, where messages could be sent
16// out of order if an extension unloaded before the activation message was sent.
17IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
18 TestRendererStartupWithConflictingMessages) {
19 // Load up an extension an begin opening an URL to a page within it. Since
20 // this will be an extension tab, the extension will be active within that
21 // process.
22 const Extension* extension =
23 LoadExtension(test_data_dir_.AppendASCII("simple_with_file"));
24 ASSERT_TRUE(extension);
25 GURL url = extension->GetResourceURL("file.html");
nick3b04f322016-08-31 19:29:1926 browser()->OpenURL(content::OpenURLParams(
27 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
28 ui::PAGE_TRANSITION_TYPED, false));
rdevlin.cronin5e510e802016-07-26 15:09:2029 // Without waiting for the tab to finish, unload the extension.
30 extension_service()->UnloadExtension(extension->id(),
limasdf0deef2042017-05-03 19:17:1731 UnloadedExtensionReason::TERMINATE);
rdevlin.cronin5e510e802016-07-26 15:09:2032 content::WebContents* web_contents =
33 browser()->tab_strip_model()->GetActiveWebContents();
34 // Wait for the web contents to stop loading.
35 content::WaitForLoadStop(web_contents);
36 EXPECT_EQ(url, web_contents->GetLastCommittedURL());
37 ASSERT_FALSE(web_contents->IsCrashed());
38}
39
rdevlin.croninc40d39f2016-08-04 23:42:1340// Tests that loading a file from a theme in a tab doesn't crash anything.
41// Another part of crbug.com/528026 and related.
42IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
43 TestRendererInitializationWithThemesTab) {
44 const Extension* extension = LoadExtensionWithFlags(
45 test_data_dir_.AppendASCII("theme"), kFlagAllowOldManifestVersions);
46 ASSERT_TRUE(extension);
47 ASSERT_TRUE(extension->is_theme());
48 GURL url = extension->GetResourceURL("manifest.json");
49 ui_test_utils::NavigateToURL(browser(), url);
50 content::WebContents* web_contents =
51 browser()->tab_strip_model()->GetActiveWebContents();
52 // Wait for the web contents to stop loading.
53 content::WaitForLoadStop(web_contents);
54 EXPECT_EQ(url, web_contents->GetLastCommittedURL());
55 ASSERT_FALSE(web_contents->IsCrashed());
56}
57
rdevlin.cronin5e510e802016-07-26 15:09:2058} // namespace extensions