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

Side by Side Diff: chrome/browser/ui/intents/intents_model_unittest.cc

Issue 7717016: Revert 97955 - First pass on intents options UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/values.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/intents/web_intents_registry.h"
11 #include "chrome/browser/webdata/web_data_service.h"
12 #include "chrome/test/base/testing_browser_process_test.h"
13 #include "chrome/browser/ui/intents/intents_model.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/models/tree_node_model.h"
16
17 class IntentsModelTest : public TestingBrowserProcessTest {
18 public:
19 IntentsModelTest()
20 : ui_thread_(BrowserThread::UI, &message_loop_),
21 db_thread_(BrowserThread::DB) {}
22
23 protected:
24 virtual void SetUp() {
25 db_thread_.Start();
26 wds_ = new WebDataService();
27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
28 wds_->Init(temp_dir_.path());
29
30 registry_.Initialize(wds_);
31 }
32
33 virtual void TearDown() {
34 if (wds_.get())
35 wds_->Shutdown();
36
37 db_thread_.Stop();
38 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
39 MessageLoop::current()->Run();
40 }
41
42 void LoadRegistry() {
43 {
44 WebIntentData provider;
45 provider.service_url = GURL("http://www.google.com/share");
46 provider.action = ASCIIToUTF16("SHARE");
47 provider.type = ASCIIToUTF16("text/url");
48 provider.title = ASCIIToUTF16("Google");
49 registry_.RegisterIntentProvider(provider);
50 }
51 {
52 WebIntentData provider;
53 provider.service_url = GURL("http://picasaweb.google.com/share");
54 provider.action = ASCIIToUTF16("EDIT");
55 provider.type = ASCIIToUTF16("image/*");
56 provider.title = ASCIIToUTF16("Picasa");
57 registry_.RegisterIntentProvider(provider);
58 }
59 {
60 WebIntentData provider;
61 provider.service_url = GURL("http://www.digg.com/share");
62 provider.action = ASCIIToUTF16("SHARE");
63 provider.type = ASCIIToUTF16("text/url");
64 provider.title = ASCIIToUTF16("Digg");
65 registry_.RegisterIntentProvider(provider);
66 }
67 }
68
69 MessageLoopForUI message_loop_;
70 BrowserThread ui_thread_;
71 BrowserThread db_thread_;
72 scoped_refptr<WebDataService> wds_;
73 WebIntentsRegistry registry_;
74 ScopedTempDir temp_dir_;
75 };
76
77 class WaitingIntentsObserver : public IntentsModel::Observer {
78 public:
79 WaitingIntentsObserver() : event_(true, false), added_(0) {}
80
81 virtual void TreeModelBeginBatch(IntentsModel* model) {}
82
83 virtual void TreeModelEndBatch(IntentsModel* model) {
84 event_.Signal();
85 MessageLoop::current()->Quit();
86 }
87
88 virtual void TreeNodesAdded(ui::TreeModel* model,
89 ui::TreeModelNode* parent,
90 int start,
91 int count) {
92 added_++;
93 }
94
95 virtual void TreeNodesRemoved(ui::TreeModel* model,
96 ui::TreeModelNode* node,
97 int start,
98 int count) {
99 }
100
101 virtual void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) {
102 }
103
104 void Wait() {
105 MessageLoop::current()->Run();
106 event_.Wait();
107 LOG(INFO) << "DONE!";
108 }
109
110 base::WaitableEvent event_;
111 int added_;
112 };
113
114 TEST_F(IntentsModelTest, NodeIDs) {
115 LoadRegistry();
116 WaitingIntentsObserver obs;
117 IntentsModel intents_model(&registry_);
118 intents_model.AddIntentsTreeObserver(&obs);
119 obs.Wait();
120
121 IntentsTreeNode* n1 = new IntentsTreeNode(ASCIIToUTF16("origin"));
122 intents_model.Add(intents_model.GetRoot(), n1,
123 intents_model.GetRoot()->child_count());
124 EXPECT_EQ(ASCIIToUTF16("origin"), intents_model.GetTreeNodeId(n1));
125
126 IntentsTreeNode* ncheck = intents_model.GetTreeNode("origin");
127 EXPECT_EQ(ncheck, n1);
128
129 base::ListValue nodes;
130 intents_model.GetChildNodeList(
131 intents_model.GetTreeNode("www.google.com"), 0, 1, &nodes);
132 EXPECT_EQ(static_cast<size_t>(1), nodes.GetSize());
133 base::DictionaryValue* dict;
134 EXPECT_TRUE(nodes.GetDictionary(0, &dict));
135
136 std::string val;
137 EXPECT_TRUE(dict->GetString("site", &val));
138 EXPECT_EQ("www.google.com", val);
139 EXPECT_TRUE(dict->GetString("name", &val));
140 EXPECT_EQ("Google", val);
141 EXPECT_TRUE(dict->GetString("url", &val));
142 EXPECT_EQ("http://www.google.com/share", val);
143 EXPECT_TRUE(dict->GetString("icon", &val));
144 EXPECT_EQ("http://www.google.com/favicon.ico", val);
145 base::ListValue* types_list;
146 EXPECT_TRUE(dict->GetList("types", &types_list));
147 EXPECT_EQ(static_cast<size_t>(1), types_list->GetSize());
148 EXPECT_TRUE(types_list->GetString(0, &val));
149 EXPECT_EQ("text/url", val);
150 bool bval;
151 EXPECT_TRUE(dict->GetBoolean("blocked", &bval));
152 EXPECT_FALSE(bval);
153 EXPECT_TRUE(dict->GetBoolean("disabled", &bval));
154 EXPECT_FALSE(bval);
155 }
156
157 TEST_F(IntentsModelTest, LoadFromWebData) {
158 LoadRegistry();
159 WaitingIntentsObserver obs;
160 IntentsModel intents_model(&registry_);
161 intents_model.AddIntentsTreeObserver(&obs);
162 obs.Wait();
163 EXPECT_EQ(3, obs.added_);
164
165 IntentsTreeNode* node = intents_model.GetTreeNode("www.google.com");
166 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node);
167 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type());
168 EXPECT_EQ(ASCIIToUTF16("www.google.com"), node->GetTitle());
169 EXPECT_EQ(1, node->child_count());
170 node = node->GetChild(0);
171 ASSERT_EQ(IntentsTreeNode::TYPE_SERVICE, node->Type());
172 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node);
173 EXPECT_EQ(ASCIIToUTF16("Google"), snode->ServiceName());
174 EXPECT_EQ(ASCIIToUTF16("SHARE"), snode->Action());
175 EXPECT_EQ(ASCIIToUTF16("http://www.google.com/share"), snode->ServiceUrl());
176 EXPECT_EQ(static_cast<size_t>(1), snode->Types().GetSize());
177 string16 stype;
178 ASSERT_TRUE(snode->Types().GetString(0, &stype));
179 EXPECT_EQ(ASCIIToUTF16("text/url"), stype);
180
181 node = intents_model.GetTreeNode("www.digg.com");
182 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node);
183 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type());
184 EXPECT_EQ(ASCIIToUTF16("www.digg.com"), node->GetTitle());
185 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/intents_model.cc ('k') | chrome/browser/ui/webui/options/intents_settings_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698