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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ref_counted_memory.h" | 6 #include "base/memory/ref_counted_memory.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/webui/theme_source.h" | 9 #include "chrome/browser/ui/webui/theme_source.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using content::BrowserThread; | 16 using content::BrowserThread; |
17 | 17 |
18 class WebUISourcesTest : public testing::Test { | 18 class WebUISourcesTest : public testing::Test { |
19 public: | 19 public: |
20 WebUISourcesTest() | 20 WebUISourcesTest() |
21 : result_data_size_(0), | 21 : result_data_size_(0), |
22 ui_thread_(BrowserThread::UI, MessageLoop::current()) {} | 22 ui_thread_(BrowserThread::UI, MessageLoop::current()) {} |
23 | 23 |
24 TestingProfile* profile() const { return profile_.get(); } | 24 TestingProfile* profile() const { return profile_.get(); } |
25 ThemeSource* theme_source() const { return theme_source_.get(); } | 25 ThemeSource* theme_source() const { return theme_source_.get(); } |
26 size_t result_data_size() const { return result_data_size_; } | 26 size_t result_data_size() const { return result_data_size_; } |
27 | 27 |
28 void StartDataRequest(const std::string& source, bool is_incognito) { | 28 void StartDataRequest(const std::string& source) { |
29 theme_source()->StartDataRequest(source, is_incognito, callback_); | 29 theme_source()->StartDataRequest(source, -1, -1, callback_); |
30 } | 30 } |
31 | 31 |
32 size_t result_data_size_; | 32 size_t result_data_size_; |
33 | 33 |
34 private: | 34 private: |
35 virtual void SetUp() { | 35 virtual void SetUp() { |
36 profile_.reset(new TestingProfile()); | 36 profile_.reset(new TestingProfile()); |
37 theme_source_.reset(new ThemeSource(profile_.get())); | 37 theme_source_.reset(new ThemeSource(profile_.get())); |
38 callback_ = base::Bind(&WebUISourcesTest::SendResponse, | 38 callback_ = base::Bind(&WebUISourcesTest::SendResponse, |
39 base::Unretained(this)); | 39 base::Unretained(this)); |
(...skipping 20 matching lines...) Expand all Loading... |
60 TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) { | 60 TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) { |
61 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css"), "text/css"); | 61 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css"), "text/css"); |
62 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css?foo"), | 62 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css?foo"), |
63 "text/css"); | 63 "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(WebUISourcesTest, 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 StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true); | 70 StartDataRequest("IDR_THEME_FRAME_INCOGNITO"); |
71 size_t min = 0; | 71 size_t min = 0; |
72 EXPECT_GT(result_data_size_, min); | 72 EXPECT_GT(result_data_size_, min); |
73 | 73 |
74 StartDataRequest("IDR_THEME_TOOLBAR", true); | 74 StartDataRequest("IDR_THEME_TOOLBAR"); |
75 EXPECT_GT(result_data_size_, min); | 75 EXPECT_GT(result_data_size_, min); |
76 } | 76 } |
77 | 77 |
78 TEST_F(WebUISourcesTest, ThemeSourceCSS) { | 78 TEST_F(WebUISourcesTest, ThemeSourceCSS) { |
79 content::TestBrowserThread io_thread(BrowserThread::IO, | 79 content::TestBrowserThread io_thread(BrowserThread::IO, |
80 MessageLoop::current()); | 80 MessageLoop::current()); |
81 // Generating the test data for the NTP CSS would just involve copying the | 81 // Generating the test data for the NTP CSS would just involve copying the |
82 // method, or being super brittle and hard-coding the result (requiring | 82 // method, or being super brittle and hard-coding the result (requiring |
83 // an update to the unittest every time the CSS template changes), so we | 83 // an update to the unittest every time the CSS template changes), so we |
84 // just check for a successful request and data that is non-null. | 84 // just check for a successful request and data that is non-null. |
85 size_t empty_size = 0; | 85 size_t empty_size = 0; |
86 | 86 |
87 StartDataRequest("css/new_tab_theme.css", false); | 87 StartDataRequest("css/new_tab_theme.css"); |
88 EXPECT_NE(result_data_size_, empty_size); | 88 EXPECT_NE(result_data_size_, empty_size); |
89 | 89 |
90 StartDataRequest("css/new_tab_theme.css?pie", false); | 90 StartDataRequest("css/new_tab_theme.css?pie"); |
91 EXPECT_NE(result_data_size_, empty_size); | 91 EXPECT_NE(result_data_size_, empty_size); |
92 | 92 |
93 // Check that we send NULL back when we can't find what we're looking for. | 93 // Check that we send NULL back when we can't find what we're looking for. |
94 StartDataRequest("css/WRONGURL", false); | 94 StartDataRequest("css/WRONGURL"); |
95 EXPECT_EQ(result_data_size_, empty_size); | 95 EXPECT_EQ(result_data_size_, empty_size); |
96 } | 96 } |
OLD | NEW |