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

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

Issue 31273002: Generate the Chrome policy schema at compile time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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/policy/browser_policy_connector.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/generate_policy_source_unittest.cc
diff --git a/chrome/browser/policy/generate_policy_source_unittest.cc b/chrome/browser/policy/generate_policy_source_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..174b486f0fedbc1216045c60bd45ada824bf0bca
--- /dev/null
+++ b/chrome/browser/policy/generate_policy_source_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "components/policy/core/common/schema.h"
+#include "policy/policy_constants.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// This unittest tests the code generated by
+// chrome/tools/build/generate_policy_source.py.
+
+namespace policy {
+
+TEST(GeneratePolicySource, ChromeSchemaData) {
+ scoped_ptr<SchemaOwner> schema_owner =
+ SchemaOwner::Wrap(GetChromeSchemaData());
+ ASSERT_TRUE(schema_owner);
+
+ Schema schema = schema_owner->schema();
+ EXPECT_EQ(base::Value::TYPE_DICTIONARY, schema.type());
+
+ Schema subschema = schema.GetAdditionalProperties();
+ EXPECT_FALSE(subschema.valid());
+
+ subschema = schema.GetProperty("no such policy exists");
+ EXPECT_FALSE(subschema.valid());
+
+ subschema = schema.GetProperty(key::kAlternateErrorPagesEnabled);
+ ASSERT_TRUE(subschema.valid());
+ EXPECT_EQ(base::Value::TYPE_BOOLEAN, subschema.type());
+
+ subschema = schema.GetProperty(key::kIncognitoModeAvailability);
+ ASSERT_TRUE(subschema.valid());
+ EXPECT_EQ(base::Value::TYPE_INTEGER, subschema.type());
+
+ subschema = schema.GetProperty(key::kProxyMode);
+ ASSERT_TRUE(subschema.valid());
+ EXPECT_EQ(base::Value::TYPE_STRING, subschema.type());
+
+ subschema = schema.GetProperty(key::kCookiesAllowedForUrls);
+ ASSERT_TRUE(subschema.valid());
+ EXPECT_EQ(base::Value::TYPE_LIST, subschema.type());
+ ASSERT_TRUE(subschema.GetItems().valid());
+ EXPECT_EQ(base::Value::TYPE_STRING, subschema.GetItems().type());
+
+ subschema = schema.GetProperty(key::kProxySettings);
+ ASSERT_TRUE(subschema.valid());
+ EXPECT_EQ(base::Value::TYPE_DICTIONARY, subschema.type());
+ EXPECT_FALSE(subschema.GetAdditionalProperties().valid());
+ EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid());
+ ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid());
+ ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid());
+ ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid());
+ ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid());
+ ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid());
+
+ // The properties are iterated in order.
+ const char* kExpectedProperties[] = {
+ key::kProxyBypassList,
+ key::kProxyMode,
+ key::kProxyPacUrl,
+ key::kProxyServer,
+ key::kProxyServerMode,
+ NULL,
+ };
+ const char** next = kExpectedProperties;
+ for (Schema::Iterator it(subschema.GetPropertiesIterator());
+ !it.IsAtEnd(); it.Advance(), ++next) {
+ ASSERT_TRUE(*next != NULL);
+ EXPECT_STREQ(*next, it.key());
+ ASSERT_TRUE(it.schema().valid());
+ EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type());
+ }
+ EXPECT_TRUE(*next == NULL);
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/policy/browser_policy_connector.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698