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

Unified Diff: chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc

Issue 2675563002: [Extensions] Remove usage of extension_action_redesign in declarativeContent (Closed)
Patch Set: . Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/declarative_content/content_action_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc
diff --git a/chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc b/chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc
index 484fd898bbc228c497ec4e80a7bcede9de8be02b..4030d5f26c60aa5d4bac56c93c8dcd7b853fab0b 100644
--- a/chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc
+++ b/chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc
@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
@@ -705,92 +706,63 @@ IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
namespace {
-// A base class that will test using the show page action capability of
-// declarative content when no page action is in the extension's manifest.
-// With the toolbar action redesign on, this succeeds; without it, it fails.
-// Abstracted out into a base class because the value of the switch needs to be
-// set during initialization.
-class ShowPageActionWithoutPageActionTest : public DeclarativeContentApiTest {
- protected:
- explicit ShowPageActionWithoutPageActionTest(bool enable_redesign)
- : enable_redesign_(enable_redesign) {}
- ~ShowPageActionWithoutPageActionTest() override {}
-
- void RunTest() {
- // Load an extension without a page action.
- std::string manifest_without_page_action = kDeclarativeContentManifest;
- base::ReplaceSubstringsAfterOffset(&manifest_without_page_action, 0,
- "\"page_action\": {},", "");
- ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action);
- ext_dir_.WriteManifest(manifest_without_page_action);
- ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
-
- const Extension* extension = LoadExtension(ext_dir_.UnpackedPath());
- ASSERT_TRUE(extension);
-
- const char kScript[] =
- "setRules([{\n"
- " conditions: [new PageStateMatcher({\n"
- " pageUrl: {hostPrefix: \"test\"}})],\n"
- " actions: [new ShowPageAction()]\n"
- "}], 'test_rule');\n";
- const char kErrorSubstr[] = "without a page action";
- std::string result =
- ExecuteScriptInBackgroundPage(extension->id(), kScript);
- if (enable_redesign_)
- EXPECT_THAT(result, testing::Not(testing::HasSubstr(kErrorSubstr)));
- else
- EXPECT_THAT(result, testing::HasSubstr(kErrorSubstr));
-
- content::WebContents* const tab =
- browser()->tab_strip_model()->GetWebContentsAt(0);
- NavigateInRenderer(tab, GURL("http://test/"));
-
- bool expect_page_action = enable_redesign_;
- ExtensionAction* page_action =
- ExtensionActionManager::Get(browser()->profile())
- ->GetPageAction(*extension);
- EXPECT_EQ(expect_page_action, page_action != nullptr);
- EXPECT_EQ(expect_page_action ? 1u : 0u,
- extension_action_test_util::GetVisiblePageActionCount(tab));
- }
+class ShowPageActionWithoutPageActionTest
+ : public DeclarativeContentApiTest,
+ public testing::WithParamInterface<bool> {};
- private:
- void SetUpCommandLine(base::CommandLine* command_line) override {
- DeclarativeContentApiTest::SetUpCommandLine(command_line);
- override_toolbar_redesign_.reset(new FeatureSwitch::ScopedOverride(
- FeatureSwitch::extension_action_redesign(), enable_redesign_));
- }
+} // namespace
- bool enable_redesign_;
- std::unique_ptr<FeatureSwitch::ScopedOverride> override_toolbar_redesign_;
- DISALLOW_COPY_AND_ASSIGN(ShowPageActionWithoutPageActionTest);
-};
+IN_PROC_BROWSER_TEST_P(ShowPageActionWithoutPageActionTest, Test) {
+ bool has_browser_action = GetParam();
+ // Load an extension without a page action.
+ std::string manifest_without_page_action = kDeclarativeContentManifest;
+ std::string replacement = has_browser_action ? "\"browser_action\": {}," : "";
+ base::ReplaceSubstringsAfterOffset(&manifest_without_page_action, 0,
+ "\"page_action\": {},",
+ replacement.c_str());
+ ASSERT_NE(kDeclarativeContentManifest, manifest_without_page_action);
+ ext_dir_.WriteManifest(manifest_without_page_action);
+ ext_dir_.WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundHelpers);
-class ShowPageActionWithoutPageActionLegacyTest
- : public ShowPageActionWithoutPageActionTest {
- protected:
- ShowPageActionWithoutPageActionLegacyTest()
- : ShowPageActionWithoutPageActionTest(false) {}
-};
+ ChromeTestExtensionLoader loader(profile());
+ scoped_refptr<const Extension> extension =
+ loader.LoadExtension(ext_dir_.UnpackedPath());
+ ASSERT_TRUE(extension);
-class ShowPageActionWithoutPageActionRedesignTest
- : public ShowPageActionWithoutPageActionTest {
- protected:
- ShowPageActionWithoutPageActionRedesignTest()
- : ShowPageActionWithoutPageActionTest(true) {}
-};
+ const char kScript[] =
+ "setRules([{\n"
+ " conditions: [new PageStateMatcher({\n"
+ " pageUrl: {hostPrefix: \"test\"}})],\n"
+ " actions: [new ShowPageAction()]\n"
+ "}], 'test_rule');\n";
+ const char kErrorSubstr[] = "without a page action";
+ std::string result = ExecuteScriptInBackgroundPage(extension->id(), kScript);
-} // namespace
+ // Extensions with no action provided are given a page action by default
+ // (for visibility reasons). If an extension has a browser action, it
+ // should cause an error.
+ if (has_browser_action)
+ EXPECT_THAT(result, testing::HasSubstr(kErrorSubstr));
+ else
+ EXPECT_THAT(result, testing::Not(testing::HasSubstr(kErrorSubstr)));
-IN_PROC_BROWSER_TEST_F(ShowPageActionWithoutPageActionLegacyTest, Test) {
- RunTest();
-}
+ content::WebContents* const tab =
+ browser()->tab_strip_model()->GetWebContentsAt(0);
+ NavigateInRenderer(tab, GURL("http://test/"));
-IN_PROC_BROWSER_TEST_F(ShowPageActionWithoutPageActionRedesignTest, Test) {
- RunTest();
+ bool expect_page_action = !has_browser_action;
+ ExtensionAction* page_action =
+ ExtensionActionManager::Get(browser()->profile())
+ ->GetPageAction(*extension);
+ EXPECT_EQ(expect_page_action, page_action != nullptr);
+ EXPECT_EQ(expect_page_action ? 1u : 0u,
+ extension_action_test_util::GetVisiblePageActionCount(tab));
}
+INSTANTIATE_TEST_CASE_P(ShowPageActionWithoutPageActionTest,
+ ShowPageActionWithoutPageActionTest,
+ ::testing::Bool());
+
IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
CanonicalizesPageStateMatcherCss) {
ext_dir_.WriteManifest(kDeclarativeContentManifest);
« no previous file with comments | « chrome/browser/extensions/api/declarative_content/content_action_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698