OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
6 #include "chrome/browser/extensions/extension_service.h" | 6 #include "chrome/browser/extensions/extension_service.h" |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
11 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
12 #include "net/test/embedded_test_server/embedded_test_server.h" | 12 #include "net/test/embedded_test_server/embedded_test_server.h" |
13 #include "ui/base/window_open_disposition.h" | 13 #include "ui/base/window_open_disposition.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 using ExtensionUnloadBrowserTest = ExtensionBrowserTest; | 17 class ExtensionUnloadBrowserTest : public ExtensionBrowserTest { |
| 18 public: |
| 19 void SetUpOnMainThread() override { |
| 20 ExtensionBrowserTest::SetUpOnMainThread(); |
| 21 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); |
| 22 } |
| 23 }; |
18 | 24 |
19 IN_PROC_BROWSER_TEST_F(ExtensionUnloadBrowserTest, TestUnload) { | 25 IN_PROC_BROWSER_TEST_F(ExtensionUnloadBrowserTest, TestUnload) { |
20 // Load an extension that installs unload and beforeunload listeners. | 26 // Load an extension that installs unload and beforeunload listeners. |
21 const Extension* extension = | 27 const Extension* extension = |
22 LoadExtension(test_data_dir_.AppendASCII("unload_listener")); | 28 LoadExtension(test_data_dir_.AppendASCII("unload_listener")); |
23 ASSERT_TRUE(extension); | 29 ASSERT_TRUE(extension); |
24 std::string id = extension->id(); | 30 std::string id = extension->id(); |
25 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 31 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
26 GURL initial_tab_url = | 32 GURL initial_tab_url = |
27 browser()->tab_strip_model()->GetWebContentsAt(0)->GetLastCommittedURL(); | 33 browser()->tab_strip_model()->GetWebContentsAt(0)->GetLastCommittedURL(); |
28 ui_test_utils::NavigateToURLWithDisposition( | 34 ui_test_utils::NavigateToURLWithDisposition( |
29 browser(), extension->GetResourceURL("page.html"), | 35 browser(), extension->GetResourceURL("page.html"), |
30 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 36 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
31 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 37 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
32 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 38 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
33 DisableExtension(id); | 39 DisableExtension(id); |
34 // There should only be one remaining web contents - the initial one. | 40 // There should only be one remaining web contents - the initial one. |
35 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 41 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
36 EXPECT_EQ( | 42 EXPECT_EQ( |
37 initial_tab_url, | 43 initial_tab_url, |
38 browser()->tab_strip_model()->GetWebContentsAt(0)->GetLastCommittedURL()); | 44 browser()->tab_strip_model()->GetWebContentsAt(0)->GetLastCommittedURL()); |
39 } | 45 } |
40 | 46 |
41 // After an extension is uninstalled, network requests from its content scripts | 47 // After an extension is uninstalled, network requests from its content scripts |
42 // should fail but not kill the renderer process. | 48 // should fail but not kill the renderer process. |
43 IN_PROC_BROWSER_TEST_F(ExtensionUnloadBrowserTest, UnloadWithContentScripts) { | 49 IN_PROC_BROWSER_TEST_F(ExtensionUnloadBrowserTest, UnloadWithContentScripts) { |
44 host_resolver()->AddRule("maps.google.com", "127.0.0.1"); | |
45 ASSERT_TRUE(embedded_test_server()->Start()); | 50 ASSERT_TRUE(embedded_test_server()->Start()); |
46 | 51 |
47 // Load an extension with a content script that has a button to send XHRs. | 52 // Load an extension with a content script that has a button to send XHRs. |
48 const Extension* extension = | 53 const Extension* extension = |
49 LoadExtension(test_data_dir_.AppendASCII("xhr_from_content_script")); | 54 LoadExtension(test_data_dir_.AppendASCII("xhr_from_content_script")); |
50 ASSERT_TRUE(extension); | 55 ASSERT_TRUE(extension); |
51 std::string id = extension->id(); | 56 std::string id = extension->id(); |
52 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 57 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
53 GURL test_url = embedded_test_server()->GetURL("/title1.html"); | 58 GURL test_url = embedded_test_server()->GetURL("/title1.html"); |
54 ui_test_utils::NavigateToURL(browser(), test_url); | 59 ui_test_utils::NavigateToURL(browser(), test_url); |
(...skipping 26 matching lines...) Expand all Loading... |
81 EXPECT_TRUE(browser() | 86 EXPECT_TRUE(browser() |
82 ->tab_strip_model() | 87 ->tab_strip_model() |
83 ->GetActiveWebContents() | 88 ->GetActiveWebContents() |
84 ->GetMainFrame() | 89 ->GetMainFrame() |
85 ->IsRenderFrameLive()); | 90 ->IsRenderFrameLive()); |
86 } | 91 } |
87 | 92 |
88 // TODO(devlin): Investigate what to do for embedded iframes. | 93 // TODO(devlin): Investigate what to do for embedded iframes. |
89 | 94 |
90 } // namespace extensions | 95 } // namespace extensions |
OLD | NEW |