| 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 "chrome/browser/extensions/extension_action.h" | 5 #include "chrome/browser/extensions/extension_action.h" |
| 6 #include "chrome/browser/extensions/extension_action_manager.h" | 6 #include "chrome/browser/extensions/extension_action_manager.h" |
| 7 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_tab_util.h" | 9 #include "chrome/browser/extensions/extension_tab_util.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/extensions/test_extension_dir.h" | 11 #include "chrome/browser/extensions/test_extension_dir.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/extensions/features/feature_channel.h" | 15 #include "chrome/common/extensions/features/feature_channel.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 18 |
| 18 namespace extensions { | 19 namespace extensions { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const char kDeclarativeContentManifest[] = | 22 const char kDeclarativeContentManifest[] = |
| 22 "{\n" | 23 "{\n" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ExecuteScriptInBackgroundPage(extension_id, kTestRule)); | 170 ExecuteScriptInBackgroundPage(extension_id, kTestRule)); |
| 170 | 171 |
| 171 content::WebContents* const tab = | 172 content::WebContents* const tab = |
| 172 browser()->tab_strip_model()->GetWebContentsAt(0); | 173 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 173 const int tab_id = ExtensionTabUtil::GetTabId(tab); | 174 const int tab_id = ExtensionTabUtil::GetTabId(tab); |
| 174 | 175 |
| 175 NavigateInRenderer(tab, GURL("http://test/")); | 176 NavigateInRenderer(tab, GURL("http://test/")); |
| 176 | 177 |
| 177 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 178 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 178 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 179 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 179 LocationBarTesting* location_bar = | 180 EXPECT_EQ(1u, extension_action_test_util::GetVisiblePageActionCount(tab)); |
| 180 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | 181 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 181 EXPECT_EQ(1, location_bar->PageActionCount()); | |
| 182 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); | |
| 183 | 182 |
| 184 ReloadExtension(extension_id); // Invalidates page_action and extension. | 183 ReloadExtension(extension_id); // Invalidates page_action and extension. |
| 185 EXPECT_EQ("test_rule", | 184 EXPECT_EQ("test_rule", |
| 186 ExecuteScriptInBackgroundPage(extension_id, kTestRule)); | 185 ExecuteScriptInBackgroundPage(extension_id, kTestRule)); |
| 187 // TODO(jyasskin): Apply new rules to existing tabs, without waiting for a | 186 // TODO(jyasskin): Apply new rules to existing tabs, without waiting for a |
| 188 // navigation. | 187 // navigation. |
| 189 NavigateInRenderer(tab, GURL("http://test/")); | 188 NavigateInRenderer(tab, GURL("http://test/")); |
| 190 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 189 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 191 EXPECT_EQ(1, location_bar->PageActionCount()); | 190 EXPECT_EQ(1u, extension_action_test_util::GetVisiblePageActionCount(tab)); |
| 192 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); | 191 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 193 | 192 |
| 194 UnloadExtension(extension_id); | 193 UnloadExtension(extension_id); |
| 195 NavigateInRenderer(tab, GURL("http://test/")); | 194 NavigateInRenderer(tab, GURL("http://test/")); |
| 196 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 195 EXPECT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 197 EXPECT_EQ(0, location_bar->PageActionCount()); | 196 EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab)); |
| 198 EXPECT_EQ(0, location_bar->PageActionVisibleCount()); | 197 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 199 } | 198 } |
| 200 | 199 |
| 201 // This tests against a renderer crash that was present during development. | 200 // This tests against a renderer crash that was present during development. |
| 202 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, | 201 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, |
| 203 DISABLED_AddExtensionMatchingExistingTabWithDeadFrames) { | 202 DISABLED_AddExtensionMatchingExistingTabWithDeadFrames) { |
| 204 ext_dir_.WriteManifest(kDeclarativeContentManifest); | 203 ext_dir_.WriteManifest(kDeclarativeContentManifest); |
| 205 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); | 204 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); |
| 206 content::WebContents* const tab = | 205 content::WebContents* const tab = |
| 207 browser()->tab_strip_model()->GetWebContentsAt(0); | 206 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 208 const int tab_id = ExtensionTabUtil::GetTabId(tab); | 207 const int tab_id = ExtensionTabUtil::GetTabId(tab); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 "}], 'test_rule');\n"), | 267 "}], 'test_rule');\n"), |
| 269 testing::HasSubstr("without a page action")); | 268 testing::HasSubstr("without a page action")); |
| 270 | 269 |
| 271 content::WebContents* const tab = | 270 content::WebContents* const tab = |
| 272 browser()->tab_strip_model()->GetWebContentsAt(0); | 271 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 273 NavigateInRenderer(tab, GURL("http://test/")); | 272 NavigateInRenderer(tab, GURL("http://test/")); |
| 274 | 273 |
| 275 EXPECT_EQ(NULL, | 274 EXPECT_EQ(NULL, |
| 276 ExtensionActionManager::Get(browser()->profile())-> | 275 ExtensionActionManager::Get(browser()->profile())-> |
| 277 GetPageAction(*extension)); | 276 GetPageAction(*extension)); |
| 278 EXPECT_EQ(0, | 277 EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab)); |
| 279 browser()->window()->GetLocationBar()->GetLocationBarForTesting()-> | |
| 280 PageActionCount()); | |
| 281 } | 278 } |
| 282 | 279 |
| 283 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, | 280 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, |
| 284 CanonicalizesPageStateMatcherCss) { | 281 CanonicalizesPageStateMatcherCss) { |
| 285 ext_dir_.WriteManifest(kDeclarativeContentManifest); | 282 ext_dir_.WriteManifest(kDeclarativeContentManifest); |
| 286 ext_dir_.WriteFile( | 283 ext_dir_.WriteFile( |
| 287 FILE_PATH_LITERAL("background.js"), | 284 FILE_PATH_LITERAL("background.js"), |
| 288 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" | 285 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" |
| 289 "function Return(obj) {\n" | 286 "function Return(obj) {\n" |
| 290 " window.domAutomationController.send('' + obj);\n" | 287 " window.domAutomationController.send('' + obj);\n" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 " new PageStateMatcher({css: ['div input']});\n" | 331 " new PageStateMatcher({css: ['div input']});\n" |
| 335 " Return('Failed to throw');\n" | 332 " Return('Failed to throw');\n" |
| 336 "} catch (e) {\n" | 333 "} catch (e) {\n" |
| 337 " Return(e.message);\n" | 334 " Return(e.message);\n" |
| 338 "}\n"), | 335 "}\n"), |
| 339 testing::ContainsRegex("compound selector.*: div input$")); | 336 testing::ContainsRegex("compound selector.*: div input$")); |
| 340 } | 337 } |
| 341 | 338 |
| 342 } // namespace | 339 } // namespace |
| 343 } // namespace extensions | 340 } // namespace extensions |
| OLD | NEW |