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

Unified Diff: chrome/browser/intents/web_intents_registry_unittest.cc

Issue 7511005: Initial version of web intents registry (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Review fixes. Created 9 years, 4 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
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/webdata/web_intents_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/intents/web_intents_registry_unittest.cc
diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d8aa4cb1b25abad5fdaf24ea3aa4d74c5e40a58d
--- /dev/null
+++ b/chrome/browser/intents/web_intents_registry_unittest.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 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/file_util.h"
+#include "base/scoped_temp_dir.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/intents/web_intents_registry.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class WebIntentsRegistryTest : public testing::Test {
+ public:
+ WebIntentsRegistryTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB) {}
+
+ protected:
+ virtual void SetUp() {
+ db_thread_.Start();
+ wds_ = new WebDataService();
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ wds_->Init(temp_dir_.path());
+ registry_.Initialize(wds_);
+ }
+
+ virtual void TearDown() {
+ if (wds_.get())
+ wds_->Shutdown();
+
+ db_thread_.Stop();
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
+ MessageLoop::current()->Run();
+ }
+
+ MessageLoopForUI message_loop_;
+ BrowserThread ui_thread_;
+ BrowserThread db_thread_;
+ scoped_refptr<WebDataService> wds_;
+ WebIntentsRegistry registry_;
+ ScopedTempDir temp_dir_;
+};
+
+// Simple consumer for WebIntentsRegistry notifications. Stores result data and
+// terminates UI thread when callback is invoked.
+class TestConsumer: public WebIntentsRegistry::Consumer {
+ public:
+ virtual void OnIntentsQueryDone(WebIntentsRegistry::QueryID id,
+ const std::vector<WebIntentData>& intents) {
+ DCHECK(id == expected_id_);
+ intents_ = intents;
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoop::current()->Quit();
+ }
+
+ // Wait for the UI message loop to terminate - happens when OnIntesQueryDone
+ // is invoked.
+ void WaitForData() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoop::current()->Run();
+ }
+
+ WebIntentsRegistry::QueryID expected_id_; // QueryID callback is tied to.
+ std::vector<WebIntentData> intents_; // Result data from callback.
+};
+
+TEST_F(WebIntentsRegistryTest, BasicTests) {
+ WebIntentData intent;
+ intent.service_url = GURL("http://google.com");
+ intent.action = ASCIIToUTF16("share");
+ intent.type = ASCIIToUTF16("image/*");
+
+ registry_.RegisterIntentProvider(intent);
+
+ intent.type = ASCIIToUTF16("video/*");
+ registry_.RegisterIntentProvider(intent);
+
+ intent.action = ASCIIToUTF16("search");
+ registry_.RegisterIntentProvider(intent);
+
+ TestConsumer consumer;
+ consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"),
+ &consumer);
+ consumer.WaitForData();
+ EXPECT_EQ(2U, consumer.intents_.size());
+
+ consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("search"),
+ &consumer);
+ consumer.WaitForData();
+ EXPECT_EQ(1U, consumer.intents_.size());
+
+ intent.action = ASCIIToUTF16("share");
+ intent.type = ASCIIToUTF16("image/*");
+ registry_.UnregisterIntentProvider(intent);
+
+ consumer.expected_id_ = registry_.GetIntentProviders(ASCIIToUTF16("share"),
+ &consumer);
+ consumer.WaitForData();
+ EXPECT_EQ(1U, consumer.intents_.size());
+}
« no previous file with comments | « chrome/browser/intents/web_intents_registry.cc ('k') | chrome/browser/webdata/web_intents_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698