OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/file_util.h" | |
6 #include "base/scoped_temp_dir.h" | |
7 #include "base/synchronization/waitable_event.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/intents/web_intents_registry.h" | |
10 #include "chrome/browser/webdata/web_data_service.h" | |
11 #include "chrome/test/base/testing_browser_process_test.h" | |
12 #include "chrome/browser/ui/intents/intents_model.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "ui/base/models/tree_node_model.h" | |
15 | |
16 TEST(IntentsModelTest, AddRemoveTest) { | |
17 | |
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
| |
18 } | |
19 | |
20 class IntentsModelDBTest : public TestingBrowserProcessTest { | |
21 public: | |
22 IntentsModelDBTest() | |
23 : ui_thread_(BrowserThread::UI, &message_loop_), | |
24 db_thread_(BrowserThread::DB) {} | |
25 | |
26 protected: | |
27 virtual void SetUp() { | |
28 db_thread_.Start(); | |
29 wds_ = new WebDataService(); | |
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
31 wds_->Init(temp_dir_.path()); | |
32 | |
33 registry_.Initialize(wds_); | |
34 } | |
35 | |
36 virtual void TearDown() { | |
37 if (wds_.get()) | |
38 wds_->Shutdown(); | |
39 | |
40 db_thread_.Stop(); | |
41 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); | |
42 MessageLoop::current()->Run(); | |
43 } | |
44 | |
45 void LoadRegistry() { | |
46 { | |
47 WebIntentData provider; | |
48 provider.service_url = GURL("http://www.google.com/share"); | |
49 provider.action = ASCIIToUTF16("SHARE"); | |
50 provider.type = ASCIIToUTF16("text/url"); | |
51 provider.title = ASCIIToUTF16("Google"); | |
52 registry_.RegisterIntentProvider(provider); | |
53 } | |
54 { | |
55 WebIntentData provider; | |
56 provider.service_url = GURL("http://picasaweb.google.com/share"); | |
57 provider.action = ASCIIToUTF16("EDIT"); | |
58 provider.type = ASCIIToUTF16("image/*"); | |
59 provider.title = ASCIIToUTF16("Picasa"); | |
60 registry_.RegisterIntentProvider(provider); | |
61 } | |
62 { | |
63 WebIntentData provider; | |
64 provider.service_url = GURL("http://www.digg.com/share"); | |
65 provider.action = ASCIIToUTF16("SHARE"); | |
66 provider.type = ASCIIToUTF16("text/url"); | |
67 provider.title = ASCIIToUTF16("Digg"); | |
68 registry_.RegisterIntentProvider(provider); | |
69 } | |
70 } | |
71 | |
72 MessageLoopForUI message_loop_; | |
73 BrowserThread ui_thread_; | |
74 BrowserThread db_thread_; | |
75 scoped_refptr<WebDataService> wds_; | |
76 WebIntentsRegistry registry_; | |
77 ScopedTempDir temp_dir_; | |
78 }; | |
79 | |
80 class WaitingIntentsObserver : public IntentsModel::Observer { | |
81 public: | |
82 WaitingIntentsObserver() : event_(true, false), added_(0) {} | |
83 | |
84 virtual void TreeModelBeginBatch(IntentsModel* model) {} | |
85 | |
86 virtual void TreeModelEndBatch(IntentsModel* model) { | |
87 event_.Signal(); | |
88 MessageLoop::current()->Quit(); | |
89 } | |
90 | |
91 virtual void TreeNodesAdded(ui::TreeModel* model, | |
92 ui::TreeModelNode* parent, | |
93 int start, | |
94 int count) { | |
95 added_++; | |
96 } | |
97 | |
98 virtual void TreeNodesRemoved(ui::TreeModel* model, | |
99 ui::TreeModelNode* node, | |
100 int start, | |
101 int count) { | |
102 } | |
103 | |
104 virtual void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) { | |
105 } | |
106 | |
107 void Wait() { | |
108 MessageLoop::current()->Run(); | |
109 event_.Wait(); | |
110 LOG(INFO) << "DONE!"; | |
111 } | |
112 | |
113 base::WaitableEvent event_; | |
114 int added_; | |
115 }; | |
116 | |
117 TEST_F(IntentsModelDBTest, LoadFromWebData) { | |
118 LoadRegistry(); | |
119 WaitingIntentsObserver obs; | |
120 IntentsModel intents_model(®istry_); | |
121 intents_model.AddIntentsTreeObserver(&obs); | |
122 obs.Wait(); | |
123 EXPECT_EQ(3, obs.added_); | |
124 | |
125 IntentsTreeNode* node = intents_model.GetTreeNode("www.google.com"); | |
126 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); | |
127 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); | |
128 EXPECT_EQ(ASCIIToUTF16("www.google.com"), node->GetTitle()); | |
129 EXPECT_EQ(1, node->child_count()); | |
130 node = node->GetChild(0); | |
131 ASSERT_EQ(IntentsTreeNode::TYPE_SERVICE, node->Type()); | |
132 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node); | |
133 EXPECT_EQ(ASCIIToUTF16("Google"), snode->ServiceName()); | |
134 EXPECT_EQ(ASCIIToUTF16("SHARE"), snode->Action()); | |
135 EXPECT_EQ(ASCIIToUTF16("http://www.google.com/share"), snode->ServiceUrl()); | |
136 EXPECT_EQ(static_cast<size_t>(1), snode->Types().GetSize()); | |
137 string16 stype; | |
138 ASSERT_TRUE(snode->Types().GetString(0, &stype)); | |
139 EXPECT_EQ(ASCIIToUTF16("text/url"), stype); | |
140 | |
141 node = intents_model.GetTreeNode("www.digg.com"); | |
142 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); | |
143 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); | |
144 EXPECT_EQ(ASCIIToUTF16("www.digg.com"), node->GetTitle()); | |
145 } | |
OLD | NEW |