Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ui/webui/favicon_source.h" | 5 #include "chrome/browser/ui/webui/favicon_source.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/browser/search/instant_service.h" | 9 #include "chrome/browser/search/instant_service.h" |
| 10 #include "chrome/browser/search/instant_service_factory.h" | 10 #include "chrome/browser/search/instant_service_factory.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 std::vector<ui::ScaleFactor> supported_scale_factors; | 28 std::vector<ui::ScaleFactor> supported_scale_factors; |
| 29 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); | 29 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 30 supported_scale_factors.push_back(ui::SCALE_FACTOR_140P); | 30 supported_scale_factors.push_back(ui::SCALE_FACTOR_140P); |
| 31 scoped_set_supported_scale_factors_.reset( | 31 scoped_set_supported_scale_factors_.reset( |
| 32 new ui::test::ScopedSetSupportedScaleFactors(supported_scale_factors)); | 32 new ui::test::ScopedSetSupportedScaleFactors(supported_scale_factors)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual ~FaviconSourceTest() { | 35 virtual ~FaviconSourceTest() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Adds a most visited item with |url| and an arbitrary title to the instant | |
| 39 // service and returns the assigned id. | |
| 40 int AddInstantMostVisitedUrlAndGetId(GURL url) { | |
| 41 InstantMostVisitedItem item; | |
| 42 item.url = GURL(url); | |
| 43 std::vector<InstantMostVisitedItem> items(1, item); | |
| 44 | |
| 45 InstantService* instant_service = | |
| 46 InstantServiceFactory::GetForProfile(profile_.get()); | |
| 47 instant_service->AddMostVisitedItems(items); | |
| 48 | |
| 49 std::vector<InstantMostVisitedItemIDPair> items_with_ids; | |
| 50 instant_service->GetCurrentMostVisitedItems(&items_with_ids); | |
| 51 CHECK_EQ(1u, items_with_ids.size()); | |
| 52 return items_with_ids[0].first; | |
| 53 } | |
| 54 | |
| 55 FaviconSource* favicon_source() const { return favicon_source_.get(); } | 38 FaviconSource* favicon_source() const { return favicon_source_.get(); } |
| 56 | 39 |
| 57 private: | 40 private: |
| 58 base::MessageLoop loop_; | 41 base::MessageLoop loop_; |
| 59 content::TestBrowserThread ui_thread_; | 42 content::TestBrowserThread ui_thread_; |
| 60 content::TestBrowserThread io_thread_; | 43 content::TestBrowserThread io_thread_; |
| 61 scoped_ptr<TestingProfile> profile_; | 44 scoped_ptr<TestingProfile> profile_; |
| 62 | 45 |
| 63 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 46 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 64 ScopedSetSupportedScaleFactors; | 47 ScopedSetSupportedScaleFactors; |
| 65 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 48 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
| 66 | 49 |
| 67 scoped_ptr<FaviconSource> favicon_source_; | 50 scoped_ptr<FaviconSource> favicon_source_; |
| 68 | 51 |
| 69 DISALLOW_COPY_AND_ASSIGN(FaviconSourceTest); | 52 DISALLOW_COPY_AND_ASSIGN(FaviconSourceTest); |
| 70 }; | 53 }; |
| 71 | 54 |
| 72 // Test parsing the chrome-search://favicon/ URLs | 55 // Test parsing the chrome-search://favicon/ URLs |
| 73 TEST_F(FaviconSourceTest, InstantParsing) { | 56 TEST_F(FaviconSourceTest, InstantParsing) { |
| 74 GURL kUrl1("http://www.google.com/"); | 57 const std::string path("chrome-search/favicon/http://www.google.com"); |
|
Jered
2013/05/31 17:34:33
What is up with the "chrome-search" prefixed to th
kmadhusu
2013/06/04 02:36:01
I missed ":/" in the path. Fixed.
| |
| 75 GURL kUrl2("http://maps.google.com/"); | |
| 76 int instant_id1 = AddInstantMostVisitedUrlAndGetId(kUrl1); | |
| 77 int instant_id2 = AddInstantMostVisitedUrlAndGetId(kUrl2); | |
| 78 | |
| 79 bool is_icon_url; | 58 bool is_icon_url; |
| 80 GURL url; | 59 GURL url; |
| 81 int size_in_dip; | 60 int size_in_dip; |
| 82 ui::ScaleFactor scale_factor; | 61 ui::ScaleFactor scale_factor; |
| 83 | 62 |
| 84 const std::string path1 = base::IntToString(instant_id1); | 63 EXPECT_TRUE(favicon_source()->ParsePath(path, &is_icon_url, &url, |
| 85 EXPECT_TRUE(favicon_source()->ParsePath(path1, &is_icon_url, &url, | |
| 86 &size_in_dip, &scale_factor)); | 64 &size_in_dip, &scale_factor)); |
| 87 EXPECT_FALSE(is_icon_url); | 65 EXPECT_FALSE(is_icon_url); |
| 88 EXPECT_EQ(kUrl1, url); | 66 EXPECT_EQ(GURL(path), url); |
| 89 EXPECT_EQ(16, size_in_dip); | |
| 90 EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); | |
| 91 | |
| 92 const std::string path2 = base::IntToString(instant_id2); | |
| 93 EXPECT_TRUE(favicon_source()->ParsePath(path2, &is_icon_url, &url, | |
| 94 &size_in_dip, &scale_factor)); | |
| 95 EXPECT_FALSE(is_icon_url); | |
| 96 EXPECT_EQ(kUrl2, url); | |
| 97 EXPECT_EQ(16, size_in_dip); | 67 EXPECT_EQ(16, size_in_dip); |
| 98 EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); | 68 EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); |
| 99 } | 69 } |
| 100 | 70 |
| 101 // Test parsing the chrome://favicon URLs | 71 // Test parsing the chrome://favicon URLs |
| 102 TEST_F(FaviconSourceTest, Parsing) { | 72 TEST_F(FaviconSourceTest, Parsing) { |
| 103 const GURL kUrl("https://www.google.ca/imghp?hl=en&tab=wi"); | 73 const GURL kUrl("https://www.google.ca/imghp?hl=en&tab=wi"); |
| 104 | 74 |
| 105 bool is_icon_url; | 75 bool is_icon_url; |
| 106 GURL url; | 76 GURL url; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 EXPECT_EQ(ui::SCALE_FACTOR_140P, scale_factor); | 182 EXPECT_EQ(ui::SCALE_FACTOR_140P, scale_factor); |
| 213 | 183 |
| 214 const std::string path14 = | 184 const std::string path14 = |
| 215 "largest/iconurl/http://www.google.com/favicon.ico"; | 185 "largest/iconurl/http://www.google.com/favicon.ico"; |
| 216 EXPECT_TRUE(favicon_source()->ParsePath(path14, &is_icon_url, &url, | 186 EXPECT_TRUE(favicon_source()->ParsePath(path14, &is_icon_url, &url, |
| 217 &size_in_dip, &scale_factor)); | 187 &size_in_dip, &scale_factor)); |
| 218 EXPECT_TRUE(is_icon_url); | 188 EXPECT_TRUE(is_icon_url); |
| 219 EXPECT_EQ("http://www.google.com/favicon.ico", url.spec()); | 189 EXPECT_EQ("http://www.google.com/favicon.ico", url.spec()); |
| 220 EXPECT_EQ(0, size_in_dip); | 190 EXPECT_EQ(0, size_in_dip); |
| 221 } | 191 } |
| OLD | NEW |