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

Unified Diff: extensions/browser/api/declarative/rules_registry_unittest.cc

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 5 years, 7 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: extensions/browser/api/declarative/rules_registry_unittest.cc
diff --git a/extensions/browser/api/declarative/rules_registry_unittest.cc b/extensions/browser/api/declarative/rules_registry_unittest.cc
index 33da872a1667d3d6a2db96dacefff7f5c57ea830..82a86788c32431bd17a9981f3b8cf7ce729bf574 100644
--- a/extensions/browser/api/declarative/rules_registry_unittest.cc
+++ b/extensions/browser/api/declarative/rules_registry_unittest.cc
@@ -7,9 +7,15 @@
#include <algorithm>
#include "base/message_loop/message_loop.h"
+#include "base/test/values_test_util.h"
+#include "base/values.h"
#include "content/public/test/test_browser_thread.h"
#include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/api/declarative/test_rules_registry.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extensions_test.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -20,7 +26,14 @@ const int key = extensions::RulesRegistryService::kDefaultRulesRegistryID;
namespace extensions {
-TEST(RulesRegistryTest, FillOptionalIdentifiers) {
+using base::test::ParseJson;
+
+class RulesRegistryTest : public ExtensionsTest {
+ public:
+ RulesRegistryTest() {}
not at google - send to devlin 2015/06/02 22:44:50 Empty constructor isn't necessary, but this needs
danduong 2015/06/03 00:18:06 Done.
+};
+
+TEST_F(RulesRegistryTest, FillOptionalIdentifiers) {
base::MessageLoopForUI message_loop;
content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop);
@@ -129,7 +142,7 @@ TEST(RulesRegistryTest, FillOptionalIdentifiers) {
message_loop.RunUntilIdle();
}
-TEST(RulesRegistryTest, FillOptionalPriority) {
+TEST_F(RulesRegistryTest, FillOptionalPriority) {
base::MessageLoopForUI message_loop;
content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop);
@@ -165,4 +178,51 @@ TEST(RulesRegistryTest, FillOptionalPriority) {
message_loop.RunUntilIdle();
}
+TEST_F(RulesRegistryTest, ExtensionWithRulesInManifest) {
Mike Wittman 2015/06/02 23:11:59 Can you add tests for handling and reporting of er
+ base::MessageLoopForUI message_loop;
+ content::TestBrowserThread thread(content::BrowserThread::UI, &message_loop);
+
+ // Create extension
+ scoped_ptr<base::DictionaryValue> manifest(
+ (base::DictionaryValue*)ParseJson(
not at google - send to devlin 2015/06/02 22:44:50 Use C++ style static_cast<>, not C style cast. Ho
danduong 2015/06/03 00:18:06 Done.
+ "{"
+ " \"name\" : \"Test\","
+ " \"version\" : \"1\","
+ " \"declarativeContent\" : {"
+ " \"onPageChanged\": ["
+ " {"
+ " \"actions\": ["
+ " {"
+ " \"instanceType\": \"declarativeContent.ShowPageAction\""
not at google - send to devlin 2015/06/02 22:44:50 This is a bit of an awkward API. Better to try to
danduong 2015/06/03 00:18:06 Where should we specify onPageChanged? How should
not at google - send to devlin 2015/06/03 16:21:44 Oh right, I suppose the event declaration syntax s
danduong 2015/06/03 16:45:53 I don't think that's valid JSON. Do you mean: "co
+ " }"
+ " ],"
+ " \"conditions\" : ["
+ " {"
+ " \"css\": [\"video\"],"
+ " \"instanceType\" : "
+ " \"declarativeContent.PageStateMatcher\""
+ " }"
+ " ]"
+ " }"
+ " ]"
+ " }"
+ "}").release());
+ scoped_refptr<Extension> extension = ExtensionBuilder()
+ .SetManifest(manifest.Pass())
+ .SetID(kExtensionId)
+ .Build();
+ ExtensionRegistry::Get(browser_context())->AddEnabled(extension);
+
+ scoped_refptr<RulesRegistry> registry = new TestRulesRegistry(
Mike Wittman 2015/06/02 23:11:59 I'm not sure why this stored in a scoped_refptr in
not at google - send to devlin 2015/06/02 23:14:40 TestRulesRegistry --> RulesRegistry --> RefCounted
Mike Wittman 2015/06/02 23:16:00 Ah, should have known.
+ browser_context(), "declarativeContent.onPageChanged",
+ content::BrowserThread::UI, NULL, key);
not at google - send to devlin 2015/06/02 22:44:50 nullptr not NULL - though I think that if you remo
danduong 2015/06/03 00:18:06 Done.
+ // Simulate what RulesRegistryService would do on extension load.
+ registry->OnExtensionLoaded(kExtensionId);
+
+ std::vector<linked_ptr<RulesRegistry::Rule>> get_rules;
+ registry->GetAllRules(kExtensionId, &get_rules);
+
+ ASSERT_EQ(1u, get_rules.size());
not at google - send to devlin 2015/06/02 22:44:50 Could you assert that this rule matches the one co
danduong 2015/06/03 00:18:06 Done.
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698