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

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

Issue 1363463002: [Extensions Toolbar] Add a finch config for the redesign (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/browser/extensions/extension_action.h" 10 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_action_test_util.h" 12 #include "chrome/browser/extensions/extension_action_test_util.h"
13 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/test_extension_dir.h" 16 #include "chrome/browser/extensions/test_extension_dir.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "components/bookmarks/browser/bookmark_model.h" 20 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "content/public/test/browser_test_utils.h" 21 #include "content/public/test/browser_test_utils.h"
22 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/extension_system.h" 23 #include "extensions/browser/extension_system.h"
24 #include "extensions/browser/test_extension_registry_observer.h"
24 #include "extensions/test/extension_test_message_listener.h" 25 #include "extensions/test/extension_test_message_listener.h"
25 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
26 27
27 namespace extensions { 28 namespace extensions {
28 namespace { 29 namespace {
29 30
30 const char kDeclarativeContentManifest[] = 31 const char kDeclarativeContentManifest[] =
31 "{\n" 32 "{\n"
32 " \"name\": \"Declarative Content apitest\",\n" 33 " \"name\": \"Declarative Content apitest\",\n"
33 " \"version\": \"0.1\",\n" 34 " \"version\": \"0.1\",\n"
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 ExecuteScriptInBackgroundPage( 637 ExecuteScriptInBackgroundPage(
637 extension->id(), 638 extension->id(),
638 "onPageChanged.removeRules(undefined, function() {\n" 639 "onPageChanged.removeRules(undefined, function() {\n"
639 " window.domAutomationController.send('removed');\n" 640 " window.domAutomationController.send('removed');\n"
640 "});\n")); 641 "});\n"));
641 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 642 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
642 } 643 }
643 644
644 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 645 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
645 ShowPageActionWithoutPageAction) { 646 ShowPageActionWithoutPageAction) {
647 // Load an extension without a page action.
646 std::string manifest_without_page_action = kDeclarativeContentManifest; 648 std::string manifest_without_page_action = kDeclarativeContentManifest;
647 base::ReplaceSubstringsAfterOffset( 649 base::ReplaceSubstringsAfterOffset(
648 &manifest_without_page_action, 0, "\"page_action\": {},", ""); 650 &manifest_without_page_action, 0, "\"page_action\": {},", "");
649 ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action); 651 ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action);
650 ext_dir_.WriteManifest(manifest_without_page_action); 652 ext_dir_.WriteManifest(manifest_without_page_action);
651 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers); 653 ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
652 const Extension* extension = LoadExtension(ext_dir_.unpacked_path());
653 ASSERT_TRUE(extension);
654 654
655 EXPECT_THAT(ExecuteScriptInBackgroundPage( 655 std::string extension_id;
656 extension->id(),
657 "setRules([{\n"
658 " conditions: [new PageStateMatcher({\n"
659 " pageUrl: {hostPrefix: \"test\"}})],\n"
660 " actions: [new ShowPageAction()]\n"
661 "}], 'test_rule');\n"),
662 testing::HasSubstr("without a page action"));
663 656
664 content::WebContents* const tab = 657 {
665 browser()->tab_strip_model()->GetWebContentsAt(0); 658 // Without the extension action redesign, the extension should get an error.
666 NavigateInRenderer(tab, GURL("http://test/")); 659 FeatureSwitch::ScopedOverride override_toolbar_redesign(
Devlin 2015/09/21 23:28:15 This first block is identical to the one of the le
Finnur 2015/09/22 14:18:32 I probably would have created a helper function in
Devlin 2015/09/23 00:28:35 I was thinking about it, and there were enough dif
660 FeatureSwitch::extension_action_redesign(), false);
661 const Extension* extension = LoadExtension(ext_dir_.unpacked_path());
662 ASSERT_TRUE(extension);
663 extension_id = extension->id();
667 664
668 EXPECT_EQ(NULL, 665 EXPECT_THAT(ExecuteScriptInBackgroundPage(
669 ExtensionActionManager::Get(browser()->profile())-> 666 extension->id(),
670 GetPageAction(*extension)); 667 "setRules([{\n"
671 EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab)); 668 " conditions: [new PageStateMatcher({\n"
669 " pageUrl: {hostPrefix: \"test\"}})],\n"
670 " actions: [new ShowPageAction()]\n"
671 "}], 'test_rule');\n"),
672 testing::HasSubstr("without a page action"));
673
674 content::WebContents* const tab =
675 browser()->tab_strip_model()->GetWebContentsAt(0);
676 NavigateInRenderer(tab, GURL("http://test/"));
677
678 // There should be no page action.
679 EXPECT_EQ(nullptr, ExtensionActionManager::Get(browser()->profile())
680 ->GetPageAction(*extension));
681 EXPECT_EQ(0u, extension_action_test_util::GetVisiblePageActionCount(tab));
682 }
683 {
684 // With the extension action redesign, it should work normally.
685 FeatureSwitch::ScopedOverride override_toolbar_redesign(
686 FeatureSwitch::extension_action_redesign(), true);
687 ReloadExtension(extension_id);
688 const Extension* extension =
689 ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(
690 extension_id);
691 ASSERT_TRUE(extension);
692
693 EXPECT_THAT(ExecuteScriptInBackgroundPage(
694 extension->id(),
695 "setRules([{\n"
696 " conditions: [new PageStateMatcher({\n"
697 " pageUrl: {hostPrefix: \"test\"}})],\n"
698 " actions: [new ShowPageAction()]\n"
699 "}], 'test_rule');\n"),
700 testing::Not(testing::HasSubstr("without a page action")));
701
702 content::WebContents* const tab =
703 browser()->tab_strip_model()->GetWebContentsAt(0);
704 NavigateInRenderer(tab, GURL("http://test/"));
705
706 // There should be a page action.
707 EXPECT_TRUE(ExtensionActionManager::Get(browser()->profile())
708 ->GetPageAction(*extension));
709 EXPECT_EQ(1u, extension_action_test_util::GetVisiblePageActionCount(tab));
710 }
672 } 711 }
673 712
674 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 713 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
675 CanonicalizesPageStateMatcherCss) { 714 CanonicalizesPageStateMatcherCss) {
676 ext_dir_.WriteManifest(kDeclarativeContentManifest); 715 ext_dir_.WriteManifest(kDeclarativeContentManifest);
677 ext_dir_.WriteFile( 716 ext_dir_.WriteFile(
678 FILE_PATH_LITERAL("background.js"), 717 FILE_PATH_LITERAL("background.js"),
679 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" 718 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n"
680 "function Return(obj) {\n" 719 "function Return(obj) {\n"
681 " window.domAutomationController.send('' + obj);\n" 720 " window.domAutomationController.send('' + obj);\n"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // action interfaces, add a test that checks that a navigation always evaluates 903 // action interfaces, add a test that checks that a navigation always evaluates
865 // consistent URL state for all conditions. i.e.: if condition1 evaluates to 904 // consistent URL state for all conditions. i.e.: if condition1 evaluates to
866 // false on url0 and true on url1, and condition2 evaluates to true on url0 and 905 // false on url0 and true on url1, and condition2 evaluates to true on url0 and
867 // false on url1, navigate from url0 to url1 and validate that no action is 906 // false on url1, navigate from url0 to url1 and validate that no action is
868 // triggered. Do the same when navigating back to url0. This kind of test is 907 // triggered. Do the same when navigating back to url0. This kind of test is
869 // unfortunately not feasible with the current implementation and the existing 908 // unfortunately not feasible with the current implementation and the existing
870 // supported conditions and actions. 909 // supported conditions and actions.
871 910
872 } // namespace 911 } // namespace
873 } // namespace extensions 912 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_action.h » ('j') | chrome/browser/extensions/extension_action.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698