rdevlin.cronin | 5e510e80 | 2016-07-26 15:09:20 | [diff] [blame] | 1 | // 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 | |
| 11 | namespace 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. |
| 17 | IN_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"); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 26 | browser()->OpenURL(content::OpenURLParams( |
| 27 | url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 28 | ui::PAGE_TRANSITION_TYPED, false)); |
rdevlin.cronin | 5e510e80 | 2016-07-26 15:09:20 | [diff] [blame] | 29 | // Without waiting for the tab to finish, unload the extension. |
| 30 | extension_service()->UnloadExtension(extension->id(), |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 31 | UnloadedExtensionReason::TERMINATE); |
rdevlin.cronin | 5e510e80 | 2016-07-26 15:09:20 | [diff] [blame] | 32 | 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.cronin | c40d39f | 2016-08-04 23:42:13 | [diff] [blame] | 40 | // Tests that loading a file from a theme in a tab doesn't crash anything. |
| 41 | // Another part of crbug.com/528026 and related. |
| 42 | IN_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.cronin | 5e510e80 | 2016-07-26 15:09:20 | [diff] [blame] | 58 | } // namespace extensions |