OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 void SetUpCommandLine(base::CommandLine* command_line) override { | 105 void SetUpCommandLine(base::CommandLine* command_line) override { |
106 ExtensionApiTest::SetUpCommandLine(command_line); | 106 ExtensionApiTest::SetUpCommandLine(command_line); |
107 // Disable background network activity as it can suddenly bring the Lazy | 107 // Disable background network activity as it can suddenly bring the Lazy |
108 // Background Page alive. | 108 // Background Page alive. |
109 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); | 109 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); |
110 command_line->AppendSwitch(::switches::kNoProxyServer); | 110 command_line->AppendSwitch(::switches::kNoProxyServer); |
111 } | 111 } |
112 | 112 |
| 113 void SetUpOnMainThread() override { |
| 114 ExtensionApiTest::SetUpOnMainThread(); |
| 115 host_resolver()->AddRule("*", "127.0.0.1"); |
| 116 } |
| 117 |
113 // Loads the extension, which temporarily starts the lazy background page | 118 // Loads the extension, which temporarily starts the lazy background page |
114 // to dispatch the onInstalled event. We wait until it shuts down again. | 119 // to dispatch the onInstalled event. We wait until it shuts down again. |
115 const Extension* LoadExtensionAndWait(const std::string& test_name) { | 120 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
116 LazyBackgroundObserver page_complete; | 121 LazyBackgroundObserver page_complete; |
117 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 122 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
118 AppendASCII(test_name); | 123 AppendASCII(test_name); |
119 const Extension* extension = LoadExtension(extdir); | 124 const Extension* extension = LoadExtension(extdir); |
120 if (extension) | 125 if (extension) |
121 page_complete.Wait(); | 126 page_complete.Wait(); |
122 return extension; | 127 return extension; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE); | 282 browser()->tab_strip_model()->active_index(), TabStripModel::CLOSE_NONE); |
278 page_complete.Wait(); | 283 page_complete.Wait(); |
279 | 284 |
280 // Lazy Background Page has been shut down. | 285 // Lazy Background Page has been shut down. |
281 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 286 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
282 } | 287 } |
283 | 288 |
284 // Tests that the lazy background page stays alive until all network requests | 289 // Tests that the lazy background page stays alive until all network requests |
285 // are complete. | 290 // are complete. |
286 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) { | 291 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForRequest) { |
287 host_resolver()->AddRule("*", "127.0.0.1"); | |
288 ASSERT_TRUE(StartEmbeddedTestServer()); | 292 ASSERT_TRUE(StartEmbeddedTestServer()); |
289 | 293 |
290 LazyBackgroundObserver page_complete; | 294 LazyBackgroundObserver page_complete; |
291 ResultCatcher catcher; | 295 ResultCatcher catcher; |
292 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 296 base::FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
293 AppendASCII("wait_for_request"); | 297 AppendASCII("wait_for_request"); |
294 const Extension* extension = LoadExtension(extdir); | 298 const Extension* extension = LoadExtension(extdir); |
295 ASSERT_TRUE(extension); | 299 ASSERT_TRUE(extension); |
296 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 300 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
297 | 301 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 // TODO: background page with timer. | 633 // TODO: background page with timer. |
630 // TODO: background page that interacts with popup. | 634 // TODO: background page that interacts with popup. |
631 | 635 |
632 // Test class to allow test cases to run in --isolate-extensions mode. | 636 // Test class to allow test cases to run in --isolate-extensions mode. |
633 class LazyBackgroundPageIsolatedExtensionsApiTest | 637 class LazyBackgroundPageIsolatedExtensionsApiTest |
634 : public LazyBackgroundPageApiTest { | 638 : public LazyBackgroundPageApiTest { |
635 public: | 639 public: |
636 LazyBackgroundPageIsolatedExtensionsApiTest() {} | 640 LazyBackgroundPageIsolatedExtensionsApiTest() {} |
637 ~LazyBackgroundPageIsolatedExtensionsApiTest() override {} | 641 ~LazyBackgroundPageIsolatedExtensionsApiTest() override {} |
638 | 642 |
639 void SetUpInProcessBrowserTestFixture() override { | 643 void SetUpOnMainThread() override { |
640 LazyBackgroundPageApiTest::SetUpInProcessBrowserTestFixture(); | 644 LazyBackgroundPageApiTest::SetUpOnMainThread(); |
641 | 645 |
642 // This is needed to allow example.com to actually resolve and load in | 646 // This is needed to allow example.com to actually resolve and load in |
643 // tests. | 647 // tests. |
644 host_resolver()->AddRule("*", "127.0.0.1"); | 648 host_resolver()->AddRule("*", "127.0.0.1"); |
645 } | 649 } |
646 | 650 |
647 void SetUpCommandLine(base::CommandLine* command_line) override { | 651 void SetUpCommandLine(base::CommandLine* command_line) override { |
648 LazyBackgroundPageApiTest::SetUpCommandLine(command_line); | 652 LazyBackgroundPageApiTest::SetUpCommandLine(command_line); |
649 command_line->AppendSwitch(switches::kIsolateExtensions); | 653 command_line->AppendSwitch(switches::kIsolateExtensions); |
650 } | 654 } |
651 | 655 |
652 private: | 656 private: |
653 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageIsolatedExtensionsApiTest); | 657 DISALLOW_COPY_AND_ASSIGN(LazyBackgroundPageIsolatedExtensionsApiTest); |
654 }; | 658 }; |
655 | 659 |
656 // Ensure that the events page of an extension is properly torn down and the | 660 // Ensure that the events page of an extension is properly torn down and the |
657 // process does not linger around when running in --isolate-extensions mode. | 661 // process does not linger around when running in --isolate-extensions mode. |
658 // See https://crbug.com/612668. | 662 // See https://crbug.com/612668. |
659 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest, | 663 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageIsolatedExtensionsApiTest, |
660 EventProcessCleanup) { | 664 EventProcessCleanup) { |
661 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); | 665 ASSERT_TRUE(LoadExtensionAndWait("event_page_with_web_iframe")); |
662 | 666 |
663 // Lazy Background Page doesn't exist anymore. | 667 // Lazy Background Page doesn't exist anymore. |
664 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); | 668 EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id())); |
665 } | 669 } |
666 | 670 |
667 } // namespace extensions | 671 } // namespace extensions |
OLD | NEW |