| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/omnibox/location_bar.h" | 13 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 19 | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 21 | 20 |
| 22 class LazyBackgroundPageApiTest : public ExtensionApiTest { | 21 class LazyBackgroundPageApiTest : public ExtensionApiTest { |
| 23 public: | 22 public: |
| 24 void SetUpCommandLine(CommandLine* command_line) { | 23 void SetUpCommandLine(CommandLine* command_line) { |
| 25 ExtensionApiTest::SetUpCommandLine(command_line); | 24 ExtensionApiTest::SetUpCommandLine(command_line); |
| 26 command_line->AppendSwitch(switches::kEnableLazyBackgroundPages); | 25 command_line->AppendSwitch(switches::kEnableLazyBackgroundPages); |
| 27 } | 26 } |
| 28 }; | 27 }; |
| 29 | 28 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 49 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 51 content::NotificationService::AllSources()); | 50 content::NotificationService::AllSources()); |
| 52 BrowserActionTestUtil(browser()).Press(0); | 51 BrowserActionTestUtil(browser()).Press(0); |
| 53 bg_pg_created.Wait(); | 52 bg_pg_created.Wait(); |
| 54 bg_pg_closed.Wait(); | 53 bg_pg_closed.Wait(); |
| 55 | 54 |
| 56 // Background page created a new tab before it closed. | 55 // Background page created a new tab before it closed. |
| 57 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 56 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 58 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); | 57 EXPECT_EQ(num_tabs_before + 1, browser()->tab_count()); |
| 59 EXPECT_EQ("chrome://extensions/", | 58 EXPECT_EQ("chrome://extensions/", |
| 60 browser()->GetSelectedTabContents()->GetURL().spec()); | 59 browser()->GetSelectedWebContents()->GetURL().spec()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, | 62 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, |
| 64 BrowserActionCreateTabAfterCallback) { | 63 BrowserActionCreateTabAfterCallback) { |
| 65 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( | 64 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( |
| 66 switches::kEnableLazyBackgroundPages)); | 65 switches::kEnableLazyBackgroundPages)); |
| 67 | 66 |
| 68 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). | 67 FilePath extdir = test_data_dir_.AppendASCII("lazy_background_page"). |
| 69 AppendASCII("browser_action_with_callback"); | 68 AppendASCII("browser_action_with_callback"); |
| 70 ASSERT_TRUE(LoadExtension(extdir)); | 69 ASSERT_TRUE(LoadExtension(extdir)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // cause lazy background pages to be created. | 117 // cause lazy background pages to be created. |
| 119 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 118 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 120 EXPECT_EQ(num_page_actions, // should be + 1 | 119 EXPECT_EQ(num_page_actions, // should be + 1 |
| 121 browser()->window()->GetLocationBar()-> | 120 browser()->window()->GetLocationBar()-> |
| 122 GetLocationBarForTesting()->PageActionVisibleCount()); | 121 GetLocationBarForTesting()->PageActionVisibleCount()); |
| 123 } | 122 } |
| 124 | 123 |
| 125 // TODO: background page with timer. | 124 // TODO: background page with timer. |
| 126 // TODO: background page that interacts with popup. | 125 // TODO: background page that interacts with popup. |
| 127 // TODO: background page with menu. | 126 // TODO: background page with menu. |
| OLD | NEW |