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

Unified Diff: chrome/browser/extensions/extension_ui_unittest.cc

Issue 487913004: Only show the checkbox for all urls when the switch is on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add Test Created 6 years, 4 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 | « no previous file | chrome/browser/ui/webui/extensions/extension_settings_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_ui_unittest.cc
diff --git a/chrome/browser/extensions/extension_ui_unittest.cc b/chrome/browser/extensions/extension_ui_unittest.cc
index 09f66c4c58fb245925f1a3ffc7c8eca8af823c54..377234ffddc26661945b2735b852d52790b40d78 100644
--- a/chrome/browser/extensions/extension_ui_unittest.cc
+++ b/chrome/browser/extensions/extension_ui_unittest.cc
@@ -8,14 +8,21 @@
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_util.h"
+#include "chrome/browser/extensions/permissions_updater.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/management_policy.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
+#include "extensions/common/extension_builder.h"
+#include "extensions/common/feature_switch.h"
+#include "extensions/common/id_util.h"
+#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
@@ -26,6 +33,10 @@
namespace extensions {
+namespace {
+const char kAllHostsPermission[] = "*://*/*";
+}
+
class ExtensionUITest : public testing::Test {
public:
ExtensionUITest()
@@ -65,6 +76,26 @@ class ExtensionUITest : public testing::Test {
return static_cast<base::DictionaryValue*>(value);
}
+ const Extension* CreateExtension(const std::string& name,
+ ListBuilder& permissions) {
+ const std::string kId = id_util::GenerateId(name);
+ scoped_refptr<const Extension> extension =
+ ExtensionBuilder().SetManifest(
+ DictionaryBuilder()
+ .Set("name", name)
+ .Set("description", "an extension")
+ .Set("manifest_version", 2)
+ .Set("version", "1.0.0")
+ .Set("permissions", permissions))
+ .SetLocation(Manifest::INTERNAL)
+ .SetID(kId)
+ .Build();
+
+ ExtensionRegistry::Get(profile())->AddEnabled(extension);
+ PermissionsUpdater(profile()).InitializePermissions(extension);
+ return extension;
+ }
+
base::DictionaryValue* CreateExtensionDetailViewFromPath(
const base::FilePath& extension_path,
const std::vector<ExtensionPage>& pages,
@@ -116,6 +147,9 @@ class ExtensionUITest : public testing::Test {
}
}
+ Profile* profile() { return profile_.get(); }
+ ExtensionSettingsHandler* handler() { return handler_.get(); }
+
base::MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
@@ -278,4 +312,78 @@ TEST_F(ExtensionUITest, PathPropagation) {
EXPECT_EQ(extension_path, base::FilePath(ui_path));
}
+// Test that the all_urls checkbox only shows up for extensions that want all
+// urls, and only when the switch is on.
+TEST_F(ExtensionUITest, ExtensionUIAllUrlsCheckbox) {
+ // Start with the switch enabled.
+ scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch(
+ new FeatureSwitch::ScopedOverride(
+ FeatureSwitch::scripts_require_action(), true));
+ // Two extensions - one with all urls, one without.
+ const Extension* all_urls_extension =
+ CreateExtension("all_urls",
+ ListBuilder().Append(kAllHostsPermission).Pass());
+ const Extension* no_urls_extension =
+ CreateExtension("no urls", ListBuilder().Pass());
+
+ scoped_ptr<base::DictionaryValue> value(
+ handler()->CreateExtensionDetailValue(
+ all_urls_extension, std::vector<ExtensionPage>(), NULL));
+ bool result = false;
+ const std::string kWantsAllUrls = "wantsAllUrls";
+ const std::string kAllowAllUrls = "allowAllUrls";
+
+ // The extension should want all urls, but not currently have it.
+ EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result));
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
+ EXPECT_FALSE(result);
+
+ // Give the extension all urls.
+ util::SetAllowedScriptingOnAllUrls(
+ all_urls_extension->id(), profile(), true);
+
+ // Now the extension should both want and have all urls.
+ value.reset(handler()->CreateExtensionDetailValue(
+ all_urls_extension, std::vector<ExtensionPage>(), NULL));
+ EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result));
+ EXPECT_TRUE(result);
+ EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
+ EXPECT_TRUE(result);
+
+ // The other extension should neither want nor have all urls.
+ value.reset(handler()->CreateExtensionDetailValue(
+ no_urls_extension, std::vector<ExtensionPage>(), NULL));
+ EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
+ EXPECT_FALSE(result);
+
+ // Turn off the switch and load another extension (so permissions are
+ // re-initialized).
+ enable_scripts_switch.reset();
+
+ // Even though the extension has the all urls preference, the checkbox
+ // shouldn't show up with the switch off.
+ value.reset(handler()->CreateExtensionDetailValue(
+ all_urls_extension, std::vector<ExtensionPage>(), NULL));
+ EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
+ EXPECT_TRUE(result);
+
+ // Load another extension with all urls (so permissions get re-init'd).
+ all_urls_extension = CreateExtension(
+ "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass());
+
+ // Even though the extension has all_urls permission, the checkbox shouldn't
+ // show up without the switch.
+ value.reset(handler()->CreateExtensionDetailValue(
+ all_urls_extension, std::vector<ExtensionPage>(), NULL));
+ EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result));
+ EXPECT_FALSE(result);
+ EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result));
+ EXPECT_FALSE(result);
+}
+
} // namespace extensions
« no previous file with comments | « no previous file | chrome/browser/ui/webui/extensions/extension_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698