| 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_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_tab_util.h" | 9 #include "chrome/browser/extensions/extension_tab_util.h" |
| 10 #include "chrome/browser/extensions/test_extension_dir.h" | 10 #include "chrome/browser/extensions/test_extension_dir.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 308 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 309 | 309 |
| 310 const std::string kRemoveTestRule2 = "removeRule('2', 'remove_rule2');\n"; | 310 const std::string kRemoveTestRule2 = "removeRule('2', 'remove_rule2');\n"; |
| 311 EXPECT_EQ("remove_rule2", | 311 EXPECT_EQ("remove_rule2", |
| 312 ExecuteScriptInBackgroundPage(extension->id(), kRemoveTestRule2)); | 312 ExecuteScriptInBackgroundPage(extension->id(), kRemoveTestRule2)); |
| 313 | 313 |
| 314 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); | 314 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Tests that rules from manifest are added and evaluated properly. |
| 318 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, RulesAddedFromManifest) { |
| 319 const char manifest[] = |
| 320 "{\n" |
| 321 " \"name\": \"Declarative Content apitest\",\n" |
| 322 " \"version\": \"0.1\",\n" |
| 323 " \"manifest_version\": 2,\n" |
| 324 " \"page_action\": {},\n" |
| 325 " \"permissions\": [\n" |
| 326 " \"declarativeContent\"\n" |
| 327 " ],\n" |
| 328 " \"event_rules\": [{\n" |
| 329 " \"event\": \"declarativeContent.onPageChanged\",\n" |
| 330 " \"actions\": [{\n" |
| 331 " \"type\": \"declarativeContent.ShowPageAction\"\n" |
| 332 " }],\n" |
| 333 " \"conditions\": [{\n" |
| 334 " \"type\": \"declarativeContent.PageStateMatcher\",\n" |
| 335 " \"pageUrl\": {\"hostPrefix\": \"test1\"}\n" |
| 336 " }]\n" |
| 337 " }]\n" |
| 338 "}\n"; |
| 339 ext_dir_.WriteManifest(manifest); |
| 340 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); |
| 341 ASSERT_TRUE(extension); |
| 342 const ExtensionAction* page_action = |
| 343 ExtensionActionManager::Get(browser()->profile()) |
| 344 ->GetPageAction(*extension); |
| 345 ASSERT_TRUE(page_action); |
| 346 |
| 347 content::WebContents* const tab = |
| 348 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 349 const int tab_id = ExtensionTabUtil::GetTabId(tab); |
| 350 |
| 351 NavigateInRenderer(tab, GURL("http://blank/")); |
| 352 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 353 NavigateInRenderer(tab, GURL("http://test1/")); |
| 354 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
| 355 NavigateInRenderer(tab, GURL("http://test2/")); |
| 356 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| 357 } |
| 358 |
| 317 // Tests that rules are not evaluated in incognito browser windows when the | 359 // Tests that rules are not evaluated in incognito browser windows when the |
| 318 // extension specifies spanning incognito mode but is not enabled for incognito. | 360 // extension specifies spanning incognito mode but is not enabled for incognito. |
| 319 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, | 361 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, |
| 320 DisabledForSpanningIncognito) { | 362 DisabledForSpanningIncognito) { |
| 321 CheckIncognito(SPANNING, false); | 363 CheckIncognito(SPANNING, false); |
| 322 } | 364 } |
| 323 | 365 |
| 324 // Tests that rules are evaluated in incognito browser windows when the | 366 // Tests that rules are evaluated in incognito browser windows when the |
| 325 // extension specifies spanning incognito mode and is enabled for incognito. | 367 // extension specifies spanning incognito mode and is enabled for incognito. |
| 326 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, EnabledForSpanningIncognito) { | 368 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, EnabledForSpanningIncognito) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 674 |
| 633 // The actual extension contents don't matter here -- we're just looking to | 675 // The actual extension contents don't matter here -- we're just looking to |
| 634 // trigger OnExtensionLoaded. | 676 // trigger OnExtensionLoaded. |
| 635 ext_dir_.WriteManifest(kDeclarativeContentManifest); | 677 ext_dir_.WriteManifest(kDeclarativeContentManifest); |
| 636 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); | 678 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); |
| 637 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path())); | 679 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path())); |
| 638 } | 680 } |
| 639 | 681 |
| 640 } // namespace | 682 } // namespace |
| 641 } // namespace extensions | 683 } // namespace extensions |
| OLD | NEW |