| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/intents/web_intents_registry.h" | 10 #include "chrome/browser/intents/web_intents_registry.h" |
| 11 #include "chrome/browser/webdata/web_data_service.h" | 11 #include "chrome/browser/webdata/web_data_service.h" |
| 12 #include "chrome/browser/ui/intents/intents_model.h" | 12 #include "chrome/browser/ui/intents/web_intents_model.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/models/tree_node_model.h" | 14 #include "ui/base/models/tree_node_model.h" |
| 15 | 15 |
| 16 class IntentsModelTest : public testing::Test { | 16 class WebIntentsModelTest : public testing::Test { |
| 17 public: | 17 public: |
| 18 IntentsModelTest() | 18 WebIntentsModelTest() |
| 19 : ui_thread_(BrowserThread::UI, &message_loop_), | 19 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 20 db_thread_(BrowserThread::DB) {} | 20 db_thread_(BrowserThread::DB) {} |
| 21 | 21 |
| 22 protected: | 22 protected: |
| 23 virtual void SetUp() { | 23 virtual void SetUp() { |
| 24 db_thread_.Start(); | 24 db_thread_.Start(); |
| 25 wds_ = new WebDataService(); | 25 wds_ = new WebDataService(); |
| 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 27 wds_->Init(temp_dir_.path()); | 27 wds_->Init(temp_dir_.path()); |
| 28 | 28 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 MessageLoopForUI message_loop_; | 68 MessageLoopForUI message_loop_; |
| 69 BrowserThread ui_thread_; | 69 BrowserThread ui_thread_; |
| 70 BrowserThread db_thread_; | 70 BrowserThread db_thread_; |
| 71 scoped_refptr<WebDataService> wds_; | 71 scoped_refptr<WebDataService> wds_; |
| 72 WebIntentsRegistry registry_; | 72 WebIntentsRegistry registry_; |
| 73 ScopedTempDir temp_dir_; | 73 ScopedTempDir temp_dir_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 class WaitingIntentsObserver : public IntentsModel::Observer { | 76 class WaitingWebIntentsObserver : public WebIntentsModel::Observer { |
| 77 public: | 77 public: |
| 78 WaitingIntentsObserver() : event_(true, false), added_(0) {} | 78 WaitingWebIntentsObserver() : event_(true, false), added_(0) {} |
| 79 | 79 |
| 80 virtual void TreeModelBeginBatch(IntentsModel* model) {} | 80 virtual void TreeModelBeginBatch(WebIntentsModel* model) {} |
| 81 | 81 |
| 82 virtual void TreeModelEndBatch(IntentsModel* model) { | 82 virtual void TreeModelEndBatch(WebIntentsModel* model) { |
| 83 event_.Signal(); | 83 event_.Signal(); |
| 84 MessageLoop::current()->Quit(); | 84 MessageLoop::current()->Quit(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void TreeNodesAdded(ui::TreeModel* model, | 87 virtual void TreeNodesAdded(ui::TreeModel* model, |
| 88 ui::TreeModelNode* parent, | 88 ui::TreeModelNode* parent, |
| 89 int start, | 89 int start, |
| 90 int count) { | 90 int count) { |
| 91 added_++; | 91 added_++; |
| 92 } | 92 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 void Wait() { | 103 void Wait() { |
| 104 MessageLoop::current()->Run(); | 104 MessageLoop::current()->Run(); |
| 105 event_.Wait(); | 105 event_.Wait(); |
| 106 LOG(INFO) << "DONE!"; | 106 LOG(INFO) << "DONE!"; |
| 107 } | 107 } |
| 108 | 108 |
| 109 base::WaitableEvent event_; | 109 base::WaitableEvent event_; |
| 110 int added_; | 110 int added_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 TEST_F(IntentsModelTest, NodeIDs) { | 113 TEST_F(WebIntentsModelTest, NodeIDs) { |
| 114 LoadRegistry(); | 114 LoadRegistry(); |
| 115 WaitingIntentsObserver obs; | 115 WaitingWebIntentsObserver obs; |
| 116 IntentsModel intents_model(®istry_); | 116 WebIntentsModel intents_model(®istry_); |
| 117 intents_model.AddIntentsTreeObserver(&obs); | 117 intents_model.AddWebIntentsTreeObserver(&obs); |
| 118 obs.Wait(); | 118 obs.Wait(); |
| 119 | 119 |
| 120 IntentsTreeNode* n1 = new IntentsTreeNode(ASCIIToUTF16("origin")); | 120 WebIntentsTreeNode* n1 = new WebIntentsTreeNode(ASCIIToUTF16("origin")); |
| 121 intents_model.Add(intents_model.GetRoot(), n1, | 121 intents_model.Add(intents_model.GetRoot(), n1, |
| 122 intents_model.GetRoot()->child_count()); | 122 intents_model.GetRoot()->child_count()); |
| 123 EXPECT_EQ(ASCIIToUTF16("origin"), intents_model.GetTreeNodeId(n1)); | 123 EXPECT_EQ(ASCIIToUTF16("origin"), intents_model.GetTreeNodeId(n1)); |
| 124 | 124 |
| 125 IntentsTreeNode* ncheck = intents_model.GetTreeNode("origin"); | 125 WebIntentsTreeNode* ncheck = intents_model.GetTreeNode("origin"); |
| 126 EXPECT_EQ(ncheck, n1); | 126 EXPECT_EQ(ncheck, n1); |
| 127 | 127 |
| 128 base::ListValue nodes; | 128 base::ListValue nodes; |
| 129 intents_model.GetChildNodeList( | 129 intents_model.GetChildNodeList( |
| 130 intents_model.GetTreeNode("www.google.com"), 0, 1, &nodes); | 130 intents_model.GetTreeNode("www.google.com"), 0, 1, &nodes); |
| 131 EXPECT_EQ(static_cast<size_t>(1), nodes.GetSize()); | 131 EXPECT_EQ(static_cast<size_t>(1), nodes.GetSize()); |
| 132 base::DictionaryValue* dict; | 132 base::DictionaryValue* dict; |
| 133 EXPECT_TRUE(nodes.GetDictionary(0, &dict)); | 133 EXPECT_TRUE(nodes.GetDictionary(0, &dict)); |
| 134 | 134 |
| 135 std::string val; | 135 std::string val; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 146 EXPECT_EQ(static_cast<size_t>(1), types_list->GetSize()); | 146 EXPECT_EQ(static_cast<size_t>(1), types_list->GetSize()); |
| 147 EXPECT_TRUE(types_list->GetString(0, &val)); | 147 EXPECT_TRUE(types_list->GetString(0, &val)); |
| 148 EXPECT_EQ("text/url", val); | 148 EXPECT_EQ("text/url", val); |
| 149 bool bval; | 149 bool bval; |
| 150 EXPECT_TRUE(dict->GetBoolean("blocked", &bval)); | 150 EXPECT_TRUE(dict->GetBoolean("blocked", &bval)); |
| 151 EXPECT_FALSE(bval); | 151 EXPECT_FALSE(bval); |
| 152 EXPECT_TRUE(dict->GetBoolean("disabled", &bval)); | 152 EXPECT_TRUE(dict->GetBoolean("disabled", &bval)); |
| 153 EXPECT_FALSE(bval); | 153 EXPECT_FALSE(bval); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(IntentsModelTest, LoadFromWebData) { | 156 TEST_F(WebIntentsModelTest, LoadFromWebData) { |
| 157 LoadRegistry(); | 157 LoadRegistry(); |
| 158 WaitingIntentsObserver obs; | 158 WaitingWebIntentsObserver obs; |
| 159 IntentsModel intents_model(®istry_); | 159 WebIntentsModel intents_model(®istry_); |
| 160 intents_model.AddIntentsTreeObserver(&obs); | 160 intents_model.AddWebIntentsTreeObserver(&obs); |
| 161 obs.Wait(); | 161 obs.Wait(); |
| 162 EXPECT_EQ(3, obs.added_); | 162 EXPECT_EQ(3, obs.added_); |
| 163 | 163 |
| 164 IntentsTreeNode* node = intents_model.GetTreeNode("www.google.com"); | 164 WebIntentsTreeNode* node = intents_model.GetTreeNode("www.google.com"); |
| 165 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); | 165 ASSERT_NE(static_cast<WebIntentsTreeNode*>(NULL), node); |
| 166 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); | 166 EXPECT_EQ(WebIntentsTreeNode::TYPE_ORIGIN, node->Type()); |
| 167 EXPECT_EQ(ASCIIToUTF16("www.google.com"), node->GetTitle()); | 167 EXPECT_EQ(ASCIIToUTF16("www.google.com"), node->GetTitle()); |
| 168 EXPECT_EQ(1, node->child_count()); | 168 EXPECT_EQ(1, node->child_count()); |
| 169 node = node->GetChild(0); | 169 node = node->GetChild(0); |
| 170 ASSERT_EQ(IntentsTreeNode::TYPE_SERVICE, node->Type()); | 170 ASSERT_EQ(WebIntentsTreeNode::TYPE_SERVICE, node->Type()); |
| 171 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node); | 171 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node); |
| 172 EXPECT_EQ(ASCIIToUTF16("Google"), snode->ServiceName()); | 172 EXPECT_EQ(ASCIIToUTF16("Google"), snode->ServiceName()); |
| 173 EXPECT_EQ(ASCIIToUTF16("SHARE"), snode->Action()); | 173 EXPECT_EQ(ASCIIToUTF16("SHARE"), snode->Action()); |
| 174 EXPECT_EQ(ASCIIToUTF16("http://www.google.com/share"), snode->ServiceUrl()); | 174 EXPECT_EQ(ASCIIToUTF16("http://www.google.com/share"), snode->ServiceUrl()); |
| 175 EXPECT_EQ(static_cast<size_t>(1), snode->Types().GetSize()); | 175 EXPECT_EQ(static_cast<size_t>(1), snode->Types().GetSize()); |
| 176 string16 stype; | 176 string16 stype; |
| 177 ASSERT_TRUE(snode->Types().GetString(0, &stype)); | 177 ASSERT_TRUE(snode->Types().GetString(0, &stype)); |
| 178 EXPECT_EQ(ASCIIToUTF16("text/url"), stype); | 178 EXPECT_EQ(ASCIIToUTF16("text/url"), stype); |
| 179 | 179 |
| 180 node = intents_model.GetTreeNode("www.digg.com"); | 180 node = intents_model.GetTreeNode("www.digg.com"); |
| 181 ASSERT_NE(static_cast<IntentsTreeNode*>(NULL), node); | 181 ASSERT_NE(static_cast<WebIntentsTreeNode*>(NULL), node); |
| 182 EXPECT_EQ(IntentsTreeNode::TYPE_ORIGIN, node->Type()); | 182 EXPECT_EQ(WebIntentsTreeNode::TYPE_ORIGIN, node->Type()); |
| 183 EXPECT_EQ(ASCIIToUTF16("www.digg.com"), node->GetTitle()); | 183 EXPECT_EQ(ASCIIToUTF16("www.digg.com"), node->GetTitle()); |
| 184 } | 184 } |
| OLD | NEW |