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

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: My efforts to implement the browser test for echo. 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..bbd43e2c9e7c9f561d3e89f9f058dc7a68098d56 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -102,7 +102,8 @@
#include "webkit/plugins/npapi/plugin_utils.h"
#include "webkit/plugins/plugin_constants.h"
#include "webkit/plugins/webplugininfo.h"
-
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/component_loader.h"
oscarpan 2013/02/06 04:38:45 Either remove or reorder the imports in future, as
#if defined(OS_CHROMEOS)
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
@@ -297,6 +298,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 +541,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);
+ }
+
oscarpan 2013/02/06 04:38:45 This seems a bit ugly. I'm trying to load my exten
Mattias Nissler (ping if slow) 2013/02/06 10:03:26 That's fine. The alternative would be to add the t
void UninstallExtension(const std::string& id, bool expect_success) {
content::WindowedNotificationObserver observer(
expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED
@@ -1314,6 +1344,41 @@ 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(),
oscarpan 2013/02/06 04:38:45 Although it seems it can access chrome.echoPrivate
Mattias Nissler (ping if slow) 2013/02/06 10:03:26 Seems like you want to attach a debugger and check
+ 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);
+ 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