OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/intents/cws_intents_registry.h" | 5 #include "chrome/browser/intents/cws_intents_registry.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/test/base/test_url_request_context_getter.h" | |
12 #include "content/test/test_url_fetcher_factory.h" | 11 #include "content/test/test_url_fetcher_factory.h" |
| 12 #include "net/url_request/url_request_test_util.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char kCWSQueryInvalid[] = | 17 const char kCWSQueryInvalid[] = |
18 "https://www-googleapis-staging.sandbox.google.com" | 18 "https://www-googleapis-staging.sandbox.google.com" |
19 "/chromewebstore/v1.1b/items/intent" | 19 "/chromewebstore/v1.1b/items/intent" |
20 "?intent=foo&mime_types=foo"; | 20 "?intent=foo&mime_types=foo"; |
21 const char kCWSResponseInvalid[] = | 21 const char kCWSResponseInvalid[] = |
22 "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"invalid\"," | 22 "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"invalid\"," |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return extensions_; | 84 return extensions_; |
85 } | 85 } |
86 | 86 |
87 void Callback(const CWSIntentsRegistry::IntentExtensionList& extensions) { | 87 void Callback(const CWSIntentsRegistry::IntentExtensionList& extensions) { |
88 extensions_ = extensions; | 88 extensions_ = extensions; |
89 } | 89 } |
90 | 90 |
91 CWSIntentsRegistry::IntentExtensionList extensions_; | 91 CWSIntentsRegistry::IntentExtensionList extensions_; |
92 FakeURLFetcherFactory test_factory_; | 92 FakeURLFetcherFactory test_factory_; |
93 | 93 |
94 private: | 94 protected: |
95 MessageLoop ui_loop_; | 95 MessageLoop ui_loop_; |
96 }; | 96 }; |
97 | 97 |
98 } // namespace | 98 } // namespace |
99 | 99 |
100 TEST_F(CWSIntentsRegistryTest, ValidQuery) { | 100 TEST_F(CWSIntentsRegistryTest, ValidQuery) { |
101 TestURLRequestContextGetter context_getter; | 101 const scoped_refptr<TestURLRequestContextGetter> context_getter( |
| 102 new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); |
102 test_factory_.SetFakeResponse(kCWSQueryValid, kCWSResponseValid, true); | 103 test_factory_.SetFakeResponse(kCWSQueryValid, kCWSResponseValid, true); |
103 | 104 |
104 CWSIntentsRegistry registry(&context_getter); | 105 CWSIntentsRegistry registry(context_getter); |
105 registry.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"), | 106 registry.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"), |
106 ASCIIToUTF16("*/png"), | 107 ASCIIToUTF16("*/png"), |
107 base::Bind(&CWSIntentsRegistryTest::Callback, | 108 base::Bind(&CWSIntentsRegistryTest::Callback, |
108 base::Unretained(this))); | 109 base::Unretained(this))); |
109 | 110 |
110 WaitForResults(); | 111 WaitForResults(); |
111 ASSERT_EQ(1UL, extensions_.size()); | 112 ASSERT_EQ(1UL, extensions_.size()); |
112 | 113 |
113 EXPECT_EQ(0, extensions_[0].num_ratings); | 114 EXPECT_EQ(0, extensions_[0].num_ratings); |
114 EXPECT_EQ(0.0, extensions_[0].average_rating); | 115 EXPECT_EQ(0.0, extensions_[0].average_rating); |
115 EXPECT_EQ(std::string(kValidManifest), UTF16ToUTF8(extensions_[0].manifest)); | 116 EXPECT_EQ(std::string(kValidManifest), UTF16ToUTF8(extensions_[0].manifest)); |
116 EXPECT_EQ(std::string(kValidIconURL), extensions_[0].icon_url.spec()); | 117 EXPECT_EQ(std::string(kValidIconURL), extensions_[0].icon_url.spec()); |
117 } | 118 } |
118 | 119 |
119 TEST_F(CWSIntentsRegistryTest, InvalidQuery) { | 120 TEST_F(CWSIntentsRegistryTest, InvalidQuery) { |
120 TestURLRequestContextGetter context_getter; | 121 const scoped_refptr<TestURLRequestContextGetter> context_getter( |
| 122 new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); |
121 test_factory_.SetFakeResponse(kCWSQueryInvalid, kCWSResponseInvalid, true); | 123 test_factory_.SetFakeResponse(kCWSQueryInvalid, kCWSResponseInvalid, true); |
122 | 124 |
123 CWSIntentsRegistry registry(&context_getter); | 125 CWSIntentsRegistry registry(context_getter); |
124 registry.GetIntentServices(ASCIIToUTF16("foo"), | 126 registry.GetIntentServices(ASCIIToUTF16("foo"), |
125 ASCIIToUTF16("foo"), | 127 ASCIIToUTF16("foo"), |
126 base::Bind(&CWSIntentsRegistryTest::Callback, | 128 base::Bind(&CWSIntentsRegistryTest::Callback, |
127 base::Unretained(this))); | 129 base::Unretained(this))); |
128 | 130 |
129 WaitForResults(); | 131 WaitForResults(); |
130 EXPECT_EQ(0UL, extensions_.size()); | 132 EXPECT_EQ(0UL, extensions_.size()); |
131 } | 133 } |
OLD | NEW |