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

Unified Diff: chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc

Issue 7033018: Handler settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove UNIT_TEST flag, replace with in_unit_test_ variable Created 9 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: chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc
index 5613be78f7f0d066e1ec5896a57a1b040e614247..06f6e8871286e3de119f3724605eae253c502389 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc
+++ b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc
@@ -40,6 +40,33 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
std::set<std::string> registered_protocols_;
};
+class NotificationCounter : public NotificationObserver {
+ public:
+ NotificationCounter()
+ : events_(0),
+ notification_registrar_() {
+ notification_registrar_.Add(this,
+ NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED,
+ NotificationService::AllSources());
+ }
+
+ ~NotificationCounter() {
+ notification_registrar_.Remove(this,
+ NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED,
+ NotificationService::AllSources());
+ }
+
+ int events() { return events_; }
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ++events_;
+ }
+
+ int events_;
+ NotificationRegistrar notification_registrar_;
+};
+
class ProtocolHandlerRegistryTest : public testing::Test {
protected:
@@ -70,6 +97,7 @@ class ProtocolHandlerRegistryTest : public testing::Test {
void ReloadProtocolHandlerRegistry() {
delegate_ = new FakeDelegate();
registry_ = new ProtocolHandlerRegistry(profile(), delegate());
+ registry_->set_in_unit_test(true);
registry_->Load();
}
@@ -78,6 +106,7 @@ class ProtocolHandlerRegistryTest : public testing::Test {
profile_->SetPrefService(new TestingPrefService());
delegate_ = new FakeDelegate();
registry_ = new ProtocolHandlerRegistry(profile(), delegate());
+ registry_->set_in_unit_test(true);
registry_->Load();
test_protocol_handler_ = CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test");
@@ -141,6 +170,13 @@ TEST_F(ProtocolHandlerRegistryTest,
ASSERT_FALSE(registry()->CanSchemeBeOverridden("test"));
}
+TEST_F(ProtocolHandlerRegistryTest, RemovingHandlerMeansItCanBeAddedAgain) {
+ registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
+ ASSERT_TRUE(registry()->CanSchemeBeOverridden("test"));
+ registry()->RemoveHandler(test_protocol_handler());
+ ASSERT_TRUE(registry()->CanSchemeBeOverridden("test"));
+}
+
TEST_F(ProtocolHandlerRegistryTest, TestStartsAsDefault) {
registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
ASSERT_TRUE(registry()->IsDefault(test_protocol_handler()));
@@ -159,9 +195,10 @@ TEST_F(ProtocolHandlerRegistryTest, TestClearDefault) {
registry()->OnAcceptRegisterProtocolHandler(ph1);
registry()->OnAcceptRegisterProtocolHandler(ph2);
- registry()->SetDefault(ph2);
+ registry()->SetDefault(ph1);
registry()->ClearDefault("test");
- ASSERT_FALSE(registry()->IsDefault(ph2));
+ ASSERT_FALSE(registry()->IsDefault(ph1));
+ ASSERT_TRUE(registry()->IsDefault(ph2));
}
TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) {
@@ -175,13 +212,13 @@ TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) {
ASSERT_TRUE(registry()->HasDefault("test"));
}
-TEST_F(ProtocolHandlerRegistryTest, TestMultipleHandlersClearsDefault) {
+TEST_F(ProtocolHandlerRegistryTest, TestMostRecentHandlerIsDefault) {
ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
registry()->OnAcceptRegisterProtocolHandler(ph1);
registry()->OnAcceptRegisterProtocolHandler(ph2);
ASSERT_FALSE(registry()->IsDefault(ph1));
- ASSERT_FALSE(registry()->IsDefault(ph2));
+ ASSERT_TRUE(registry()->IsDefault(ph2));
}
TEST_F(ProtocolHandlerRegistryTest, TestSetDefault) {
@@ -220,7 +257,7 @@ TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandler) {
registry()->RemoveHandler(ph1);
ASSERT_FALSE(registry()->IsRegistered(ph1));
- ASSERT_FALSE(registry()->HasHandler("test"));
+ ASSERT_FALSE(registry()->IsHandledProtocol("test"));
}
TEST_F(ProtocolHandlerRegistryTest, TestIsRegistered) {
@@ -236,6 +273,7 @@ TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) {
ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
ProtocolHandler ph3 = CreateProtocolHandler("test", "test3");
+
registry()->OnAcceptRegisterProtocolHandler(ph1);
registry()->OnAcceptRegisterProtocolHandler(ph2);
registry()->OnAcceptRegisterProtocolHandler(ph3);
@@ -244,3 +282,54 @@ TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) {
registry()->RemoveHandler(ph1);
ASSERT_FALSE(registry()->IsDefault(ph1));
}
+
+TEST_F(ProtocolHandlerRegistryTest, TestGetHandlersFor) {
+ ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
+ ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
+ ProtocolHandler ph3 = CreateProtocolHandler("test", "test3");
+ registry()->OnAcceptRegisterProtocolHandler(ph1);
+ registry()->OnAcceptRegisterProtocolHandler(ph2);
+ registry()->OnAcceptRegisterProtocolHandler(ph3);
+
+ const ProtocolHandlerRegistry::ProtocolHandlerList* handlers =
+ registry()->GetHandlersFor("test");
+ ASSERT_TRUE(handlers != NULL);
+ ASSERT_EQ(ph1, (*handlers)[0]);
+ ASSERT_EQ(ph2, (*handlers)[1]);
+ ASSERT_EQ(ph3, (*handlers)[2]);
+}
+
+TEST_F(ProtocolHandlerRegistryTest, TestGetHandledProtocols) {
+ std::vector<std::string> protocols;
+ registry()->GetHandledProtocols(&protocols);
+ ASSERT_EQ((size_t) 0, protocols.size());
+
+ registry()->GetHandlersFor("test");
+
+ protocols.clear();
+ registry()->GetHandledProtocols(&protocols);
+ ASSERT_EQ((size_t) 0, protocols.size());
+}
+
+TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocol) {
+ registry()->GetHandlersFor("test");
+ ASSERT_FALSE(registry()->IsHandledProtocol("test"));
+}
+
+TEST_F(ProtocolHandlerRegistryTest, TestNotifications) {
+ ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
+ NotificationCounter counter;
+
+ registry()->OnAcceptRegisterProtocolHandler(ph1);
+ ASSERT_EQ(1, counter.events());
+
+ registry()->Disable();
+ ASSERT_EQ(2, counter.events());
+
+ registry()->Enable();
+ ASSERT_EQ(3, counter.events());
+
+ registry()->RemoveHandler(ph1);
+ ASSERT_EQ(4, counter.events());
+}
+// TODO add unit tests for notifications

Powered by Google App Engine
This is Rietveld 408576698