Chromium Code Reviews| Index: chrome/browser/ui/intents/intents_model_unittest.cc |
| diff --git a/chrome/browser/ui/intents/intents_model_unittest.cc b/chrome/browser/ui/intents/intents_model_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2c213386fda36403cf76f4db3b6d16167059b7a |
| --- /dev/null |
| +++ b/chrome/browser/ui/intents/intents_model_unittest.cc |
| @@ -0,0 +1,145 @@ |
| +// 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/synchronization/waitable_event.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/intents/web_intents_registry.h" |
| +#include "chrome/browser/webdata/web_data_service.h" |
| +#include "chrome/test/base/testing_browser_process_test.h" |
| +#include "chrome/browser/ui/intents/intents_model.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/models/tree_node_model.h" |
| + |
| +TEST(IntentsModelTest, AddRemoveTest) { |
| + |
|
James Hawkins
2011/08/17 03:18:39
Deadcode.
Greg Billock
2011/08/17 18:49:50
Now filled in below. (Uploaded this last night bef
|
| +} |
| + |
| +class IntentsModelDBTest : public TestingBrowserProcessTest { |
| + public: |
| + IntentsModelDBTest() |
| + : 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(); |
| + } |
| + |
| + void LoadRegistry() { |
| + { |
| + WebIntentData provider; |
| + provider.service_url = GURL("http://www.google.com/share"); |
| + provider.action = ASCIIToUTF16("SHARE"); |
| + provider.type = ASCIIToUTF16("text/url"); |
| + provider.title = ASCIIToUTF16("Google"); |
| + registry_.RegisterIntentProvider(provider); |
| + } |
| + { |
| + WebIntentData provider; |
| + provider.service_url = GURL("http://picasaweb.google.com/share"); |
| + provider.action = ASCIIToUTF16("EDIT"); |
| + provider.type = ASCIIToUTF16("image/*"); |
| + provider.title = ASCIIToUTF16("Picasa"); |
| + registry_.RegisterIntentProvider(provider); |
| + } |
| + { |
| + WebIntentData provider; |
| + provider.service_url = GURL("http://www.digg.com/share"); |
| + provider.action = ASCIIToUTF16("SHARE"); |
| + provider.type = ASCIIToUTF16("text/url"); |
| + provider.title = ASCIIToUTF16("Digg"); |
| + registry_.RegisterIntentProvider(provider); |
| + } |
| + } |
| + |
| + MessageLoopForUI message_loop_; |
| + BrowserThread ui_thread_; |
| + BrowserThread db_thread_; |
| + scoped_refptr<WebDataService> wds_; |
| + WebIntentsRegistry registry_; |
| + ScopedTempDir temp_dir_; |
| +}; |
| + |
| +class WaitingIntentsObserver : public IntentsModel::Observer { |
| + public: |
| + WaitingIntentsObserver() : event_(true, false), added_(0) {} |
| + |
| + virtual void TreeModelBeginBatch(IntentsModel* model) {} |
| + |
| + virtual void TreeModelEndBatch(IntentsModel* model) { |
| + event_.Signal(); |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + virtual void TreeNodesAdded(ui::TreeModel* model, |
| + ui::TreeModelNode* parent, |
| + int start, |
| + int count) { |
| + added_++; |
| + } |
| + |
| + virtual void TreeNodesRemoved(ui::TreeModel* model, |
| + ui::TreeModelNode* node, |
| + int start, |
| + int count) { |
| + } |
| + |
| + virtual void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) { |
| + } |
| + |
| + void Wait() { |
| + MessageLoop::current()->Run(); |
| + event_.Wait(); |
| + LOG(INFO) << "DONE!"; |
| + } |
| + |
| + base::WaitableEvent event_; |
| + int added_; |
| +}; |
| + |
| +TEST_F(IntentsModelDBTest, LoadFromWebData) { |
| + LoadRegistry(); |
| + WaitingIntentsObserver obs; |
| + IntentsModel intents_model(®istry_); |
| + intents_model.AddIntentsTreeObserver(&obs); |
| + obs.Wait(); |
| + EXPECT_EQ(3, obs.added_); |
| + |
| + IntentsTreeNode* node = intents_model.GetTreeNode("www.google.com"); |
| + ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); |
| + EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); |
| + EXPECT_EQ(ASCIIToUTF16("www.google.com"), node->GetTitle()); |
| + EXPECT_EQ(1, node->child_count()); |
| + node = node->GetChild(0); |
| + ASSERT_EQ(IntentsTreeNode::TYPE_SERVICE, node->Type()); |
| + ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node); |
| + EXPECT_EQ(ASCIIToUTF16("Google"), snode->ServiceName()); |
| + EXPECT_EQ(ASCIIToUTF16("SHARE"), snode->Action()); |
| + EXPECT_EQ(ASCIIToUTF16("http://www.google.com/share"), snode->ServiceUrl()); |
| + EXPECT_EQ(static_cast<size_t>(1), snode->Types().GetSize()); |
| + string16 stype; |
| + ASSERT_TRUE(snode->Types().GetString(0, &stype)); |
| + EXPECT_EQ(ASCIIToUTF16("text/url"), stype); |
| + |
| + node = intents_model.GetTreeNode("www.digg.com"); |
| + ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); |
| + EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); |
| + EXPECT_EQ(ASCIIToUTF16("www.digg.com"), node->GetTitle()); |
| +} |