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

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 12147004: Disable/enable echo for enterprise device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 10 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
Index: chrome/browser/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index b455aacdb744a3900df031421414f102ee9391d9..15208f66703f0ecbf3168dd17c24c2d70b1af0b8 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/download/download_prefs.h"
+#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
@@ -102,7 +103,6 @@
#include "webkit/plugins/npapi/plugin_utils.h"
#include "webkit/plugins/plugin_constants.h"
#include "webkit/plugins/webplugininfo.h"
-
#if defined(OS_CHROMEOS)
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
@@ -297,6 +297,21 @@ bool IsWebGLEnabled(content::WebContents* contents) {
return result;
}
+#if defined(OS_CHROMEOS)
+// Checks if redeeming cros offers is allowed in the given WebContents.
+bool CheckAllowRedeemCrosOffers(content::WebContents* contents) {
+ bool result = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ "chrome.echoPrivate.allowRedeemOffers("
+ " function(allow) {"
+ " domAutomationController.send(allow);"
+ " });",
+ &result));
+ return result;
+}
+#endif
+
bool IsJavascriptEnabled(content::WebContents* contents) {
scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue(
contents->GetRenderViewHost(), "123");
@@ -525,6 +540,20 @@ class PolicyTest : public InProcessBrowserTest {
return details.ptr();
}
+ const extensions::Extension* LoadExtensionAsComponent(
+ const FilePath& path) {
+ ExtensionService* service = extension_service();
+
+ std::string manifest;
+ if (!file_util::ReadFileToString(
+ path.Append(extensions::Extension::kManifestFilename),
+ &manifest))
+ return NULL;
+
+ std::string extension_id = service->component_loader()->Add(manifest, path);
+ return service->extensions()->GetByID(extension_id);
+ }
+
void UninstallExtension(const std::string& id, bool expect_success) {
content::WindowedNotificationObserver observer(
expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED
@@ -1314,6 +1343,40 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, IncognitoEnabled) {
EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive());
}
+#if defined(OS_CHROMEOS)
+IN_PROC_BROWSER_TEST_F(PolicyTest, AllowRedeemChromeOsRegistrationOffers) {
+ FilePath extension_path(ui_test_utils::GetTestFilePath(
+ FilePath(kTestExtensionsDir), FilePath("echo_component_extension")));
+ LoadExtensionAsComponent(extension_path);
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ contents->GetController().LoadURL(
+ GURL("chrome-extension://lbgjohhgghbkcgejgklgcmfijhbheflf/main.html"),
+ content::Referrer(),
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+ content::WaitForLoadStop(contents);
+ EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents));
+ PolicyMap policies;
+
+ // Allow offer redemption and verify the flag value through js.
+ policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_MACHINE,
+ base::Value::CreateBooleanValue(false));
+ UpdateProviderPolicy(policies);
oscarpan 2013/02/07 00:40:39 So I confirmed that all other codes are running as
Mattias Nissler (ping if slow) 2013/02/07 10:45:57 Ah, that makes sense!
+ EXPECT_FALSE(CheckAllowRedeemCrosOffers(contents));
+
+ // Disallow offer redemption and verify the flag value through js.
+ policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers,
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_MACHINE,
+ base::Value::CreateBooleanValue(true));
+ UpdateProviderPolicy(policies);
+ EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents));
+}
+#endif
+
IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) {
// Verifies that Javascript can be disabled.
content::WebContents* contents =

Powered by Google App Engine
This is Rietveld 408576698