Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc

Issue 2314363002: extensions: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Comment addressed Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 "\"incognito\": \"split\""); 138 "\"incognito\": \"split\"");
139 ASSERT_NE(kDeclarativeContentManifest, manifest); 139 ASSERT_NE(kDeclarativeContentManifest, manifest);
140 } 140 }
141 ext_dir_.WriteManifest(manifest); 141 ext_dir_.WriteManifest(manifest);
142 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), 142 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"),
143 kIncognitoSpecificBackground); 143 kIncognitoSpecificBackground);
144 144
145 ExtensionTestMessageListener ready("ready", false); 145 ExtensionTestMessageListener ready("ready", false);
146 ExtensionTestMessageListener ready_incognito("ready (split)", false); 146 ExtensionTestMessageListener ready_incognito("ready (split)", false);
147 147
148 const Extension* extension = is_enabled_in_incognito ? 148 const Extension* extension =
149 LoadExtensionIncognito(ext_dir_.unpacked_path()) : 149 is_enabled_in_incognito ? LoadExtensionIncognito(ext_dir_.UnpackedPath())
150 LoadExtension(ext_dir_.unpacked_path()); 150 : LoadExtension(ext_dir_.UnpackedPath());
151 ASSERT_TRUE(extension); 151 ASSERT_TRUE(extension);
152 152
153 Browser* incognito_browser = CreateIncognitoBrowser(); 153 Browser* incognito_browser = CreateIncognitoBrowser();
154 const ExtensionAction* incognito_page_action = 154 const ExtensionAction* incognito_page_action =
155 ExtensionActionManager::Get(incognito_browser->profile())-> 155 ExtensionActionManager::Get(incognito_browser->profile())->
156 GetPageAction(*extension); 156 GetPageAction(*extension);
157 ASSERT_TRUE(incognito_page_action); 157 ASSERT_TRUE(incognito_page_action);
158 158
159 ASSERT_TRUE(ready.WaitUntilSatisfied()); 159 ASSERT_TRUE(ready.WaitUntilSatisfied());
160 if (is_enabled_in_incognito && mode == SPLIT) 160 if (is_enabled_in_incognito && mode == SPLIT)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 void DeclarativeContentApiTest::CheckBookmarkEvents(bool match_is_bookmarked) { 202 void DeclarativeContentApiTest::CheckBookmarkEvents(bool match_is_bookmarked) {
203 ext_dir_.WriteManifest(kDeclarativeContentManifest); 203 ext_dir_.WriteManifest(kDeclarativeContentManifest);
204 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 204 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
205 205
206 content::WebContents* const tab = 206 content::WebContents* const tab =
207 browser()->tab_strip_model()->GetWebContentsAt(0); 207 browser()->tab_strip_model()->GetWebContentsAt(0);
208 const int tab_id = ExtensionTabUtil::GetTabId(tab); 208 const int tab_id = ExtensionTabUtil::GetTabId(tab);
209 209
210 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 210 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
211 ASSERT_TRUE(extension); 211 ASSERT_TRUE(extension);
212 const ExtensionAction* page_action = ExtensionActionManager::Get( 212 const ExtensionAction* page_action = ExtensionActionManager::Get(
213 browser()->profile())->GetPageAction(*extension); 213 browser()->profile())->GetPageAction(*extension);
214 ASSERT_TRUE(page_action); 214 ASSERT_TRUE(page_action);
215 215
216 NavigateInRenderer(tab, GURL("http://test1/")); 216 NavigateInRenderer(tab, GURL("http://test1/"));
217 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 217 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
218 218
219 static const char kSetIsBookmarkedRule[] = 219 static const char kSetIsBookmarkedRule[] =
220 "setRules([{\n" 220 "setRules([{\n"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 "}\n" 271 "}\n"
272 "\n" 272 "\n"
273 "var testEvent = chrome.declarativeContent.onPageChanged;\n" 273 "var testEvent = chrome.declarativeContent.onPageChanged;\n"
274 "\n" 274 "\n"
275 "testEvent.removeRules(undefined, function() {\n" 275 "testEvent.removeRules(undefined, function() {\n"
276 " testEvent.addRules([rule], function() {\n" 276 " testEvent.addRules([rule], function() {\n"
277 " chrome.test.sendMessage(\"ready\")\n" 277 " chrome.test.sendMessage(\"ready\")\n"
278 " });\n" 278 " });\n"
279 "});\n"); 279 "});\n");
280 ExtensionTestMessageListener ready("ready", false); 280 ExtensionTestMessageListener ready("ready", false);
281 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 281 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
282 ASSERT_TRUE(extension); 282 ASSERT_TRUE(extension);
283 const ExtensionAction* page_action = 283 const ExtensionAction* page_action =
284 ExtensionActionManager::Get(browser()->profile())-> 284 ExtensionActionManager::Get(browser()->profile())->
285 GetPageAction(*extension); 285 GetPageAction(*extension);
286 ASSERT_TRUE(page_action); 286 ASSERT_TRUE(page_action);
287 287
288 ASSERT_TRUE(ready.WaitUntilSatisfied()); 288 ASSERT_TRUE(ready.WaitUntilSatisfied());
289 content::WebContents* const tab = 289 content::WebContents* const tab =
290 browser()->tab_strip_model()->GetWebContentsAt(0); 290 browser()->tab_strip_model()->GetWebContentsAt(0);
291 const int tab_id = ExtensionTabUtil::GetTabId(tab); 291 const int tab_id = ExtensionTabUtil::GetTabId(tab);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 "};\n" 351 "};\n"
352 "\n" 352 "\n"
353 "var testEvent = chrome.declarativeContent.onPageChanged;\n" 353 "var testEvent = chrome.declarativeContent.onPageChanged;\n"
354 "\n" 354 "\n"
355 "testEvent.removeRules(undefined, function() {\n" 355 "testEvent.removeRules(undefined, function() {\n"
356 " testEvent.addRules([rule1, rule2], function() {\n" 356 " testEvent.addRules([rule1, rule2], function() {\n"
357 " chrome.test.sendMessage(\"ready\");\n" 357 " chrome.test.sendMessage(\"ready\");\n"
358 " });\n" 358 " });\n"
359 "});\n"); 359 "});\n");
360 ExtensionTestMessageListener ready("ready", false); 360 ExtensionTestMessageListener ready("ready", false);
361 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 361 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
362 ASSERT_TRUE(extension); 362 ASSERT_TRUE(extension);
363 const ExtensionAction* page_action = 363 const ExtensionAction* page_action =
364 ExtensionActionManager::Get(browser()->profile()) 364 ExtensionActionManager::Get(browser()->profile())
365 ->GetPageAction(*extension); 365 ->GetPageAction(*extension);
366 ASSERT_TRUE(page_action); 366 ASSERT_TRUE(page_action);
367 367
368 ASSERT_TRUE(ready.WaitUntilSatisfied()); 368 ASSERT_TRUE(ready.WaitUntilSatisfied());
369 content::WebContents* const tab = 369 content::WebContents* const tab =
370 browser()->tab_strip_model()->GetWebContentsAt(0); 370 browser()->tab_strip_model()->GetWebContentsAt(0);
371 const int tab_id = ExtensionTabUtil::GetTabId(tab); 371 const int tab_id = ExtensionTabUtil::GetTabId(tab);
372 372
373 // This navigation matches both rules. 373 // This navigation matches both rules.
374 NavigateInRenderer(tab, GURL("http://test1/")); 374 NavigateInRenderer(tab, GURL("http://test1/"));
375 375
376 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 376 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
377 } 377 }
378 378
379 // Tests that the rules are evaluated at the time they are added or removed. 379 // Tests that the rules are evaluated at the time they are added or removed.
380 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, RulesEvaluatedOnAddRemove) { 380 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, RulesEvaluatedOnAddRemove) {
381 ext_dir_.WriteManifest(kDeclarativeContentManifest); 381 ext_dir_.WriteManifest(kDeclarativeContentManifest);
382 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 382 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
383 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 383 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
384 ASSERT_TRUE(extension); 384 ASSERT_TRUE(extension);
385 const ExtensionAction* page_action = 385 const ExtensionAction* page_action =
386 ExtensionActionManager::Get(browser()->profile())-> 386 ExtensionActionManager::Get(browser()->profile())->
387 GetPageAction(*extension); 387 GetPageAction(*extension);
388 ASSERT_TRUE(page_action); 388 ASSERT_TRUE(page_action);
389 389
390 content::WebContents* const tab = 390 content::WebContents* const tab =
391 browser()->tab_strip_model()->GetWebContentsAt(0); 391 browser()->tab_strip_model()->GetWebContentsAt(0);
392 const int tab_id = ExtensionTabUtil::GetTabId(tab); 392 const int tab_id = ExtensionTabUtil::GetTabId(tab);
393 393
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 " \"actions\": [{\n" 443 " \"actions\": [{\n"
444 " \"type\": \"declarativeContent.ShowPageAction\"\n" 444 " \"type\": \"declarativeContent.ShowPageAction\"\n"
445 " }],\n" 445 " }],\n"
446 " \"conditions\": [{\n" 446 " \"conditions\": [{\n"
447 " \"type\": \"declarativeContent.PageStateMatcher\",\n" 447 " \"type\": \"declarativeContent.PageStateMatcher\",\n"
448 " \"pageUrl\": {\"hostPrefix\": \"test1\"}\n" 448 " \"pageUrl\": {\"hostPrefix\": \"test1\"}\n"
449 " }]\n" 449 " }]\n"
450 " }]\n" 450 " }]\n"
451 "}\n"; 451 "}\n";
452 ext_dir_.WriteManifest(manifest); 452 ext_dir_.WriteManifest(manifest);
453 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 453 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
454 ASSERT_TRUE(extension); 454 ASSERT_TRUE(extension);
455 const ExtensionAction* page_action = 455 const ExtensionAction* page_action =
456 ExtensionActionManager::Get(browser()->profile()) 456 ExtensionActionManager::Get(browser()->profile())
457 ->GetPageAction(*extension); 457 ->GetPageAction(*extension);
458 ASSERT_TRUE(page_action); 458 ASSERT_TRUE(page_action);
459 459
460 content::WebContents* const tab = 460 content::WebContents* const tab =
461 browser()->tab_strip_model()->GetWebContentsAt(0); 461 browser()->tab_strip_model()->GetWebContentsAt(0);
462 const int tab_id = ExtensionTabUtil::GetTabId(tab); 462 const int tab_id = ExtensionTabUtil::GetTabId(tab);
463 463
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 content::WebContents* const incognito_tab = 502 content::WebContents* const incognito_tab =
503 incognito_browser->tab_strip_model()->GetWebContentsAt(0); 503 incognito_browser->tab_strip_model()->GetWebContentsAt(0);
504 const int incognito_tab_id = ExtensionTabUtil::GetTabId(incognito_tab); 504 const int incognito_tab_id = ExtensionTabUtil::GetTabId(incognito_tab);
505 505
506 NavigateInRenderer(incognito_tab, GURL("http://test_normal/")); 506 NavigateInRenderer(incognito_tab, GURL("http://test_normal/"));
507 507
508 ext_dir_.WriteManifest(kDeclarativeContentManifest); 508 ext_dir_.WriteManifest(kDeclarativeContentManifest);
509 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), 509 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"),
510 kIncognitoSpecificBackground); 510 kIncognitoSpecificBackground);
511 ExtensionTestMessageListener ready("ready", false); 511 ExtensionTestMessageListener ready("ready", false);
512 const Extension* extension = LoadExtensionIncognito(ext_dir_.unpacked_path()); 512 const Extension* extension = LoadExtensionIncognito(ext_dir_.UnpackedPath());
513 ASSERT_TRUE(extension); 513 ASSERT_TRUE(extension);
514 ASSERT_TRUE(ready.WaitUntilSatisfied()); 514 ASSERT_TRUE(ready.WaitUntilSatisfied());
515 515
516 const ExtensionAction* incognito_page_action = 516 const ExtensionAction* incognito_page_action =
517 ExtensionActionManager::Get(incognito_browser->profile())-> 517 ExtensionActionManager::Get(incognito_browser->profile())->
518 GetPageAction(*extension); 518 GetPageAction(*extension);
519 ASSERT_TRUE(incognito_page_action); 519 ASSERT_TRUE(incognito_page_action);
520 520
521 // The page action should be shown. 521 // The page action should be shown.
522 EXPECT_TRUE(incognito_page_action->GetIsVisible(incognito_tab_id)); 522 EXPECT_TRUE(incognito_page_action->GetIsVisible(incognito_tab_id));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // Fails on XP: http://crbug.com/515717 592 // Fails on XP: http://crbug.com/515717
593 #define MAYBE_UninstallWhileActivePageAction \ 593 #define MAYBE_UninstallWhileActivePageAction \
594 DISABLED_UninstallWhileActivePageAction 594 DISABLED_UninstallWhileActivePageAction
595 #else 595 #else
596 #define MAYBE_UninstallWhileActivePageAction UninstallWhileActivePageAction 596 #define MAYBE_UninstallWhileActivePageAction UninstallWhileActivePageAction
597 #endif 597 #endif
598 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 598 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
599 MAYBE_UninstallWhileActivePageAction) { 599 MAYBE_UninstallWhileActivePageAction) {
600 ext_dir_.WriteManifest(kDeclarativeContentManifest); 600 ext_dir_.WriteManifest(kDeclarativeContentManifest);
601 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 601 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
602 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 602 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
603 ASSERT_TRUE(extension); 603 ASSERT_TRUE(extension);
604 const std::string extension_id = extension->id(); 604 const std::string extension_id = extension->id();
605 const ExtensionAction* page_action = ExtensionActionManager::Get( 605 const ExtensionAction* page_action = ExtensionActionManager::Get(
606 browser()->profile())->GetPageAction(*extension); 606 browser()->profile())->GetPageAction(*extension);
607 ASSERT_TRUE(page_action); 607 ASSERT_TRUE(page_action);
608 608
609 const std::string kTestRule = 609 const std::string kTestRule =
610 "setRules([{\n" 610 "setRules([{\n"
611 " conditions: [new PageStateMatcher({\n" 611 " conditions: [new PageStateMatcher({\n"
612 " pageUrl: {hostPrefix: \"test\"}})],\n" 612 " pageUrl: {hostPrefix: \"test\"}})],\n"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 content::WebContents* const tab = 651 content::WebContents* const tab =
652 browser()->tab_strip_model()->GetWebContentsAt(0); 652 browser()->tab_strip_model()->GetWebContentsAt(0);
653 const int tab_id = ExtensionTabUtil::GetTabId(tab); 653 const int tab_id = ExtensionTabUtil::GetTabId(tab);
654 654
655 ASSERT_TRUE(content::ExecuteScript( 655 ASSERT_TRUE(content::ExecuteScript(
656 tab, "document.body.innerHTML = '<iframe src=\"http://test2\">';")); 656 tab, "document.body.innerHTML = '<iframe src=\"http://test2\">';"));
657 // Replace the iframe to destroy its WebFrame. 657 // Replace the iframe to destroy its WebFrame.
658 ASSERT_TRUE(content::ExecuteScript( 658 ASSERT_TRUE(content::ExecuteScript(
659 tab, "document.body.innerHTML = '<span class=\"foo\">';")); 659 tab, "document.body.innerHTML = '<span class=\"foo\">';"));
660 660
661 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 661 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
662 ASSERT_TRUE(extension); 662 ASSERT_TRUE(extension);
663 const ExtensionAction* page_action = ExtensionActionManager::Get( 663 const ExtensionAction* page_action = ExtensionActionManager::Get(
664 browser()->profile())->GetPageAction(*extension); 664 browser()->profile())->GetPageAction(*extension);
665 ASSERT_TRUE(page_action); 665 ASSERT_TRUE(page_action);
666 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 666 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
667 667
668 EXPECT_EQ("rule0", 668 EXPECT_EQ("rule0",
669 ExecuteScriptInBackgroundPage( 669 ExecuteScriptInBackgroundPage(
670 extension->id(), 670 extension->id(),
671 "setRules([{\n" 671 "setRules([{\n"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 709
710 void RunTest() { 710 void RunTest() {
711 // Load an extension without a page action. 711 // Load an extension without a page action.
712 std::string manifest_without_page_action = kDeclarativeContentManifest; 712 std::string manifest_without_page_action = kDeclarativeContentManifest;
713 base::ReplaceSubstringsAfterOffset(&manifest_without_page_action, 0, 713 base::ReplaceSubstringsAfterOffset(&manifest_without_page_action, 0,
714 "\"page_action\": {},", ""); 714 "\"page_action\": {},", "");
715 ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action); 715 ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action);
716 ext_dir_.WriteManifest(manifest_without_page_action); 716 ext_dir_.WriteManifest(manifest_without_page_action);
717 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 717 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
718 718
719 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 719 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
720 ASSERT_TRUE(extension); 720 ASSERT_TRUE(extension);
721 721
722 const char kScript[] = 722 const char kScript[] =
723 "setRules([{\n" 723 "setRules([{\n"
724 " conditions: [new PageStateMatcher({\n" 724 " conditions: [new PageStateMatcher({\n"
725 " pageUrl: {hostPrefix: \"test\"}})],\n" 725 " pageUrl: {hostPrefix: \"test\"}})],\n"
726 " actions: [new ShowPageAction()]\n" 726 " actions: [new ShowPageAction()]\n"
727 "}], 'test_rule');\n"; 727 "}], 'test_rule');\n";
728 const char kErrorSubstr[] = "without a page action"; 728 const char kErrorSubstr[] = "without a page action";
729 std::string result = 729 std::string result =
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 792
793 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 793 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
794 CanonicalizesPageStateMatcherCss) { 794 CanonicalizesPageStateMatcherCss) {
795 ext_dir_.WriteManifest(kDeclarativeContentManifest); 795 ext_dir_.WriteManifest(kDeclarativeContentManifest);
796 ext_dir_.WriteFile( 796 ext_dir_.WriteFile(
797 FILE_PATH_LITERAL("background.js"), 797 FILE_PATH_LITERAL("background.js"),
798 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" 798 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n"
799 "function Return(obj) {\n" 799 "function Return(obj) {\n"
800 " window.domAutomationController.send('' + obj);\n" 800 " window.domAutomationController.send('' + obj);\n"
801 "}\n"); 801 "}\n");
802 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 802 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
803 ASSERT_TRUE(extension); 803 ASSERT_TRUE(extension);
804 804
805 EXPECT_EQ("input[type=\"password\"]", 805 EXPECT_EQ("input[type=\"password\"]",
806 ExecuteScriptInBackgroundPage( 806 ExecuteScriptInBackgroundPage(
807 extension->id(), 807 extension->id(),
808 "var psm = new PageStateMatcher(\n" 808 "var psm = new PageStateMatcher(\n"
809 " {css: [\"input[type='password']\"]});\n" 809 " {css: [\"input[type='password']\"]});\n"
810 "Return(psm.css);")); 810 "Return(psm.css);"));
811 811
812 EXPECT_THAT(ExecuteScriptInBackgroundPage( 812 EXPECT_THAT(ExecuteScriptInBackgroundPage(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 // Add a web contents to the tab strip in a way that doesn't trigger 869 // Add a web contents to the tab strip in a way that doesn't trigger
870 // NOTIFICATION_TAB_ADDED. 870 // NOTIFICATION_TAB_ADDED.
871 content::WebContents* contents = content::WebContents::Create( 871 content::WebContents* contents = content::WebContents::Create(
872 content::WebContents::CreateParams(profile())); 872 content::WebContents::CreateParams(profile()));
873 browser()->tab_strip_model()->AppendWebContents(contents, false); 873 browser()->tab_strip_model()->AppendWebContents(contents, false);
874 874
875 // The actual extension contents don't matter here -- we're just looking to 875 // The actual extension contents don't matter here -- we're just looking to
876 // trigger OnExtensionLoaded. 876 // trigger OnExtensionLoaded.
877 ext_dir_.WriteManifest(kDeclarativeContentManifest); 877 ext_dir_.WriteManifest(kDeclarativeContentManifest);
878 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 878 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
879 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path())); 879 ASSERT_TRUE(LoadExtension(ext_dir_.UnpackedPath()));
880 } 880 }
881 881
882 // https://crbug.com/501225 882 // https://crbug.com/501225
883 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 883 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
884 PendingWebContentsClearedOnRemoveRules) { 884 PendingWebContentsClearedOnRemoveRules) {
885 ext_dir_.WriteManifest(kDeclarativeContentManifest); 885 ext_dir_.WriteManifest(kDeclarativeContentManifest);
886 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 886 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
887 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 887 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
888 ASSERT_TRUE(extension); 888 ASSERT_TRUE(extension);
889 const ExtensionAction* page_action = ExtensionActionManager::Get( 889 const ExtensionAction* page_action = ExtensionActionManager::Get(
890 browser()->profile())->GetPageAction(*extension); 890 browser()->profile())->GetPageAction(*extension);
891 ASSERT_TRUE(page_action); 891 ASSERT_TRUE(page_action);
892 892
893 // Create two tabs. 893 // Create two tabs.
894 content::WebContents* const tab1 = 894 content::WebContents* const tab1 =
895 browser()->tab_strip_model()->GetWebContentsAt(0); 895 browser()->tab_strip_model()->GetWebContentsAt(0);
896 896
897 AddTabAtIndex(1, GURL("http://test2/"), ui::PAGE_TRANSITION_LINK); 897 AddTabAtIndex(1, GURL("http://test2/"), ui::PAGE_TRANSITION_LINK);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 #else 936 #else
937 #define MAYBE_RemoveAllRulesAfterExtensionUninstall \ 937 #define MAYBE_RemoveAllRulesAfterExtensionUninstall \
938 RemoveAllRulesAfterExtensionUninstall 938 RemoveAllRulesAfterExtensionUninstall
939 #endif 939 #endif
940 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 940 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
941 MAYBE_RemoveAllRulesAfterExtensionUninstall) { 941 MAYBE_RemoveAllRulesAfterExtensionUninstall) {
942 ext_dir_.WriteManifest(kDeclarativeContentManifest); 942 ext_dir_.WriteManifest(kDeclarativeContentManifest);
943 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 943 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
944 944
945 // Load the extension, add a rule, then uninstall the extension. 945 // Load the extension, add a rule, then uninstall the extension.
946 const Extension* extension = LoadExtension(ext_dir_.unpacked_path()); 946 const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
947 ASSERT_TRUE(extension); 947 ASSERT_TRUE(extension);
948 948
949 const std::string kAddTestRule = 949 const std::string kAddTestRule =
950 "addRules([{\n" 950 "addRules([{\n"
951 " id: '1',\n" 951 " id: '1',\n"
952 " conditions: [],\n" 952 " conditions: [],\n"
953 " actions: [new ShowPageAction()]\n" 953 " actions: [new ShowPageAction()]\n"
954 "}], 'add_rule');\n"; 954 "}], 'add_rule');\n";
955 EXPECT_EQ("add_rule", 955 EXPECT_EQ("add_rule",
956 ExecuteScriptInBackgroundPage(extension->id(), kAddTestRule)); 956 ExecuteScriptInBackgroundPage(extension->id(), kAddTestRule));
957 957
958 ExtensionService* extension_service = extensions::ExtensionSystem::Get( 958 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
959 browser()->profile())->extension_service(); 959 browser()->profile())->extension_service();
960 960
961 base::string16 error; 961 base::string16 error;
962 ASSERT_TRUE(extension_service->UninstallExtension( 962 ASSERT_TRUE(extension_service->UninstallExtension(
963 extension->id(), 963 extension->id(),
964 UNINSTALL_REASON_FOR_TESTING, 964 UNINSTALL_REASON_FOR_TESTING,
965 base::Bind(&base::DoNothing), 965 base::Bind(&base::DoNothing),
966 &error)); 966 &error));
967 ASSERT_EQ(base::ASCIIToUTF16(""), error); 967 ASSERT_EQ(base::ASCIIToUTF16(""), error);
968 968
969 // Reload the extension, then add and remove a rule. 969 // Reload the extension, then add and remove a rule.
970 extension = LoadExtension(ext_dir_.unpacked_path()); 970 extension = LoadExtension(ext_dir_.UnpackedPath());
971 ASSERT_TRUE(extension); 971 ASSERT_TRUE(extension);
972 972
973 EXPECT_EQ("add_rule", 973 EXPECT_EQ("add_rule",
974 ExecuteScriptInBackgroundPage(extension->id(), kAddTestRule)); 974 ExecuteScriptInBackgroundPage(extension->id(), kAddTestRule));
975 975
976 const std::string kRemoveTestRule1 = "removeRule('1', 'remove_rule1');\n"; 976 const std::string kRemoveTestRule1 = "removeRule('1', 'remove_rule1');\n";
977 EXPECT_EQ("remove_rule1", 977 EXPECT_EQ("remove_rule1",
978 ExecuteScriptInBackgroundPage(extension->id(), kRemoveTestRule1)); 978 ExecuteScriptInBackgroundPage(extension->id(), kRemoveTestRule1));
979 } 979 }
980 980
981 981
982 // TODO(wittman): Once ChromeContentRulesRegistry operates on condition and 982 // TODO(wittman): Once ChromeContentRulesRegistry operates on condition and
983 // action interfaces, add a test that checks that a navigation always evaluates 983 // action interfaces, add a test that checks that a navigation always evaluates
984 // consistent URL state for all conditions. i.e.: if condition1 evaluates to 984 // consistent URL state for all conditions. i.e.: if condition1 evaluates to
985 // false on url0 and true on url1, and condition2 evaluates to true on url0 and 985 // false on url0 and true on url1, and condition2 evaluates to true on url0 and
986 // false on url1, navigate from url0 to url1 and validate that no action is 986 // false on url1, navigate from url0 to url1 and validate that no action is
987 // triggered. Do the same when navigating back to url0. This kind of test is 987 // triggered. Do the same when navigating back to url0. This kind of test is
988 // unfortunately not feasible with the current implementation and the existing 988 // unfortunately not feasible with the current implementation and the existing
989 // supported conditions and actions. 989 // supported conditions and actions.
990 990
991 } // namespace 991 } // namespace
992 } // namespace extensions 992 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698