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/extensions/api/mdns/mdns_apitest.cc

Issue 23437015: Initial chrome.mdns API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable test for WinDbg Created 7 years, 3 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/extensions/api/mdns/mdns_apitest.cc
diff --git a/chrome/browser/extensions/api/mdns/mdns_apitest.cc b/chrome/browser/extensions/api/mdns/mdns_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec8d477c7f6c28cf00ab0bd7db43d651b9acb84d
--- /dev/null
+++ b/chrome/browser/extensions/api/mdns/mdns_apitest.cc
@@ -0,0 +1,134 @@
+// Copyright (c) 2012 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 "base/command_line.h"
+#include "chrome/browser/extensions/api/mdns/mdns_api.h"
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/mdns.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using extensions::DnsSdRegistry;
+using ::testing::A;
+using ::testing::_;
+
+namespace api = extensions::api;
+
+namespace {
+
+class MockDnsSdRegistry : public DnsSdRegistry {
+ public:
+ explicit MockDnsSdRegistry(extensions::MDnsAPI* api) : api_(api) {}
+ virtual ~MockDnsSdRegistry() {}
+
+ MOCK_METHOD1(AddObserver, void(DnsSdObserver* observer));
+ MOCK_METHOD1(RemoveObserver, void(DnsSdObserver* observer));
+ MOCK_METHOD1(RegisterDnsSdListener, void(std::string service_type));
+ MOCK_METHOD1(UnregisterDnsSdListener, void(std::string service_type));
+
+ void DispatchMDnsEvent(const std::string& service_type,
+ const DnsSdServiceList& services) {
+ api_->OnDnsSdEvent(service_type, services);
+ }
+
+ private:
+ extensions::DnsSdRegistry::DnsSdObserver* api_;
+};
+
+class MDnsAPITest : public ExtensionApiTest {
+ public:
+ MDnsAPITest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ ExtensionApiTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitchASCII(
+ switches::kWhitelistedExtensionID, "ddchlicdkolnonkihahngkmmmjnjlkkf");
+ }
+
+ void SetUpTestDnsSdRegistry() {
+ extensions::MDnsAPI* api = extensions::MDnsAPI::Get(profile());
+ dns_sd_registry_ = new MockDnsSdRegistry(api);
+ // Transfers ownership of the registry instance.
+ api->SetDnsSdRegistryForTesting(
+ make_scoped_ptr<DnsSdRegistry>(dns_sd_registry_).Pass());
+ }
+
+ protected:
+ MockDnsSdRegistry* dns_sd_registry_;
+};
+
+} // namespace
+
+// TODO(justinlin): Win Dbg has a workaround that makes RunExtensionSubtest
+// always return true without actually running the test. Remove when fixed.
+#if defined(OS_WIN) && !defined(NDEBUG)
+#define MAYBE_RegisterListener DISABLED_RegisterListener
+#else
+#define MAYBE_RegisterListener RegisterListener
+#endif
+// Test loading extension, registering an MDNS listener and dispatching events.
+IN_PROC_BROWSER_TEST_F(MDnsAPITest, MAYBE_RegisterListener) {
+ const std::string& service_type = "_googlecast._tcp.local";
+ SetUpTestDnsSdRegistry();
+
+ EXPECT_CALL(*dns_sd_registry_, RegisterDnsSdListener(service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_, UnregisterDnsSdListener(service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_,
+ RemoveObserver(A<extensions::DnsSdRegistry::DnsSdObserver*>()))
+ .Times(1);
+
+ EXPECT_TRUE(RunExtensionSubtest("mdns/api", "register_listener.html"))
+ << message_;
+
+ ResultCatcher catcher;
+ // Dispatch 3 events, one of which should not be sent to the test extension.
+ std::vector<std::string> services;
+ services.push_back("test");
+
+ dns_sd_registry_->DispatchMDnsEvent(service_type, services);
+ dns_sd_registry_->DispatchMDnsEvent("_uninteresting._tcp.local", services);
+ dns_sd_registry_->DispatchMDnsEvent(service_type, services);
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+}
+
+// TODO(justinlin): Win Dbg has a workaround that makes RunExtensionSubtest
+// always return true without actually running the test. Remove when fixed.
+#if defined(OS_WIN) && !defined(NDEBUG)
+#define MAYBE_RegisterMultipleListeners DISABLED_RegisterMultipleListeners
+#else
+#define MAYBE_RegisterMultipleListeners RegisterMultipleListeners
+#endif
+// Test loading extension and registering multiple listeners.
+IN_PROC_BROWSER_TEST_F(MDnsAPITest, MAYBE_RegisterMultipleListeners) {
+ const std::string& service_type = "_googlecast._tcp.local";
+ const std::string& test_service_type = "_testing._tcp.local";
+ SetUpTestDnsSdRegistry();
+
+ EXPECT_CALL(*dns_sd_registry_, RegisterDnsSdListener(service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_, UnregisterDnsSdListener(service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_, RegisterDnsSdListener(test_service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_, UnregisterDnsSdListener(test_service_type))
+ .Times(1);
+ EXPECT_CALL(*dns_sd_registry_,
+ RemoveObserver(A<extensions::DnsSdRegistry::DnsSdObserver*>()))
+ .Times(1);
+
+ EXPECT_TRUE(RunExtensionSubtest("mdns/api",
+ "register_multiple_listeners.html"))
+ << message_;
+
+ ResultCatcher catcher;
+ std::vector<std::string> services;
+ services.push_back("test");
+
+ dns_sd_registry_->DispatchMDnsEvent(service_type, services);
+ dns_sd_registry_->DispatchMDnsEvent(test_service_type, services);
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+}
« no previous file with comments | « chrome/browser/extensions/api/mdns/mdns_api.cc ('k') | chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698