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/ref_counted_memory.h" | 5 #include "base/ref_counted_memory.h" |
6 #include "chrome/browser/browser_thread.h" | 6 #include "chrome/browser/browser_thread.h" |
7 #include "chrome/browser/dom_ui/web_ui_theme_source.h" | 7 #include "chrome/browser/dom_ui/web_ui_theme_source.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/themes/browser_theme_provider.h" | 9 #include "chrome/browser/themes/browser_theme_provider.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 result_request_id_ = request_id; | 26 result_request_id_ = request_id; |
27 } | 27 } |
28 | 28 |
29 int result_request_id_; | 29 int result_request_id_; |
30 size_t result_data_size_; | 30 size_t result_data_size_; |
31 | 31 |
32 private: | 32 private: |
33 ~MockThemeSource() {} | 33 ~MockThemeSource() {} |
34 }; | 34 }; |
35 | 35 |
36 class DOMUISourcesTest : public testing::Test { | 36 class WebUISourcesTest : public testing::Test { |
37 public: | 37 public: |
38 DOMUISourcesTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 38 WebUISourcesTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
39 | 39 |
40 TestingProfile* profile() const { return profile_.get(); } | 40 TestingProfile* profile() const { return profile_.get(); } |
41 MockThemeSource* theme_source() const { return theme_source_.get(); } | 41 MockThemeSource* theme_source() const { return theme_source_.get(); } |
42 private: | 42 private: |
43 virtual void SetUp() { | 43 virtual void SetUp() { |
44 profile_.reset(new TestingProfile()); | 44 profile_.reset(new TestingProfile()); |
45 profile_->InitThemes(); | 45 profile_->InitThemes(); |
46 theme_source_ = new MockThemeSource(profile_.get()); | 46 theme_source_ = new MockThemeSource(profile_.get()); |
47 } | 47 } |
48 | 48 |
49 virtual void TearDown() { | 49 virtual void TearDown() { |
50 theme_source_ = NULL; | 50 theme_source_ = NULL; |
51 profile_.reset(NULL); | 51 profile_.reset(NULL); |
52 } | 52 } |
53 | 53 |
54 MessageLoop loop_; | 54 MessageLoop loop_; |
55 BrowserThread ui_thread_; | 55 BrowserThread ui_thread_; |
56 | 56 |
57 scoped_ptr<TestingProfile> profile_; | 57 scoped_ptr<TestingProfile> profile_; |
58 scoped_refptr<MockThemeSource> theme_source_; | 58 scoped_refptr<MockThemeSource> theme_source_; |
59 }; | 59 }; |
60 | 60 |
61 TEST_F(DOMUISourcesTest, ThemeSourceMimeTypes) { | 61 TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) { |
62 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css"); | 62 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css"); |
63 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css"); | 63 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css"); |
64 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png"); | 64 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png"); |
65 } | 65 } |
66 | 66 |
67 TEST_F(DOMUISourcesTest, ThemeSourceImages) { | 67 TEST_F(WebUISourcesTest, ThemeSourceImages) { |
68 // We used to PNGEncode the images ourselves, but encoder differences | 68 // We used to PNGEncode the images ourselves, but encoder differences |
69 // invalidated that. We now just check that the image exists. | 69 // invalidated that. We now just check that the image exists. |
70 theme_source()->StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true, 1); | 70 theme_source()->StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true, 1); |
71 size_t min = 0; | 71 size_t min = 0; |
72 EXPECT_EQ(theme_source()->result_request_id_, 1); | 72 EXPECT_EQ(theme_source()->result_request_id_, 1); |
73 EXPECT_GT(theme_source()->result_data_size_, min); | 73 EXPECT_GT(theme_source()->result_data_size_, min); |
74 | 74 |
75 theme_source()->StartDataRequest("IDR_THEME_TOOLBAR", true, 2); | 75 theme_source()->StartDataRequest("IDR_THEME_TOOLBAR", true, 2); |
76 EXPECT_EQ(theme_source()->result_request_id_, 2); | 76 EXPECT_EQ(theme_source()->result_request_id_, 2); |
77 EXPECT_GT(theme_source()->result_data_size_, min); | 77 EXPECT_GT(theme_source()->result_data_size_, min); |
78 } | 78 } |
79 | 79 |
80 TEST_F(DOMUISourcesTest, ThemeSourceCSS) { | 80 TEST_F(WebUISourcesTest, ThemeSourceCSS) { |
81 BrowserThread io_thread(BrowserThread::IO, MessageLoop::current()); | 81 BrowserThread io_thread(BrowserThread::IO, MessageLoop::current()); |
82 // Generating the test data for the NTP CSS would just involve copying the | 82 // Generating the test data for the NTP CSS would just involve copying the |
83 // method, or being super brittle and hard-coding the result (requiring | 83 // method, or being super brittle and hard-coding the result (requiring |
84 // an update to the unittest every time the CSS template changes), so we | 84 // an update to the unittest every time the CSS template changes), so we |
85 // just check for a successful request and data that is non-null. | 85 // just check for a successful request and data that is non-null. |
86 size_t empty_size = 0; | 86 size_t empty_size = 0; |
87 | 87 |
88 theme_source()->StartDataRequest("css/newtab.css", false, 1); | 88 theme_source()->StartDataRequest("css/newtab.css", false, 1); |
89 EXPECT_EQ(theme_source()->result_request_id_, 1); | 89 EXPECT_EQ(theme_source()->result_request_id_, 1); |
90 EXPECT_NE(theme_source()->result_data_size_, empty_size); | 90 EXPECT_NE(theme_source()->result_data_size_, empty_size); |
91 | 91 |
92 theme_source()->StartDataRequest("css/newtab.css?pie", false, 3); | 92 theme_source()->StartDataRequest("css/newtab.css?pie", false, 3); |
93 EXPECT_EQ(theme_source()->result_request_id_, 3); | 93 EXPECT_EQ(theme_source()->result_request_id_, 3); |
94 EXPECT_NE(theme_source()->result_data_size_, empty_size); | 94 EXPECT_NE(theme_source()->result_data_size_, empty_size); |
95 | 95 |
96 // Check that we send NULL back when we can't find what we're looking for. | 96 // Check that we send NULL back when we can't find what we're looking for. |
97 theme_source()->StartDataRequest("css/WRONGURL", false, 7); | 97 theme_source()->StartDataRequest("css/WRONGURL", false, 7); |
98 EXPECT_EQ(theme_source()->result_request_id_, 7); | 98 EXPECT_EQ(theme_source()->result_request_id_, 7); |
99 EXPECT_EQ(theme_source()->result_data_size_, empty_size); | 99 EXPECT_EQ(theme_source()->result_data_size_, empty_size); |
100 } | 100 } |
OLD | NEW |