| 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/memory/ref_counted_memory.h" | 5 #include "base/memory/ref_counted_memory.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/webui/theme_source.h" | 8 #include "chrome/browser/ui/webui/theme_source.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 MessageLoop loop_; | 56 MessageLoop loop_; |
| 57 content::TestBrowserThread ui_thread_; | 57 content::TestBrowserThread ui_thread_; |
| 58 | 58 |
| 59 scoped_ptr<TestingProfile> profile_; | 59 scoped_ptr<TestingProfile> profile_; |
| 60 scoped_refptr<MockThemeSource> theme_source_; | 60 scoped_refptr<MockThemeSource> theme_source_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) { | 63 TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) { |
| 64 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css"); | 64 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css"), "text/css"); |
| 65 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css"); | 65 EXPECT_EQ(theme_source()->GetMimeType("css/new_tab_theme.css?foo"), |
| 66 "text/css"); |
| 66 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png"); | 67 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png"); |
| 67 } | 68 } |
| 68 | 69 |
| 69 TEST_F(WebUISourcesTest, ThemeSourceImages) { | 70 TEST_F(WebUISourcesTest, ThemeSourceImages) { |
| 70 // We used to PNGEncode the images ourselves, but encoder differences | 71 // We used to PNGEncode the images ourselves, but encoder differences |
| 71 // invalidated that. We now just check that the image exists. | 72 // invalidated that. We now just check that the image exists. |
| 72 theme_source()->StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true, 1); | 73 theme_source()->StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true, 1); |
| 73 size_t min = 0; | 74 size_t min = 0; |
| 74 EXPECT_EQ(theme_source()->result_request_id_, 1); | 75 EXPECT_EQ(theme_source()->result_request_id_, 1); |
| 75 EXPECT_GT(theme_source()->result_data_size_, min); | 76 EXPECT_GT(theme_source()->result_data_size_, min); |
| 76 | 77 |
| 77 theme_source()->StartDataRequest("IDR_THEME_TOOLBAR", true, 2); | 78 theme_source()->StartDataRequest("IDR_THEME_TOOLBAR", true, 2); |
| 78 EXPECT_EQ(theme_source()->result_request_id_, 2); | 79 EXPECT_EQ(theme_source()->result_request_id_, 2); |
| 79 EXPECT_GT(theme_source()->result_data_size_, min); | 80 EXPECT_GT(theme_source()->result_data_size_, min); |
| 80 } | 81 } |
| 81 | 82 |
| 82 TEST_F(WebUISourcesTest, ThemeSourceCSS) { | 83 TEST_F(WebUISourcesTest, ThemeSourceCSS) { |
| 83 content::TestBrowserThread io_thread(BrowserThread::IO, | 84 content::TestBrowserThread io_thread(BrowserThread::IO, |
| 84 MessageLoop::current()); | 85 MessageLoop::current()); |
| 85 // Generating the test data for the NTP CSS would just involve copying the | 86 // Generating the test data for the NTP CSS would just involve copying the |
| 86 // method, or being super brittle and hard-coding the result (requiring | 87 // method, or being super brittle and hard-coding the result (requiring |
| 87 // an update to the unittest every time the CSS template changes), so we | 88 // an update to the unittest every time the CSS template changes), so we |
| 88 // just check for a successful request and data that is non-null. | 89 // just check for a successful request and data that is non-null. |
| 89 size_t empty_size = 0; | 90 size_t empty_size = 0; |
| 90 | 91 |
| 91 theme_source()->StartDataRequest("css/newtab.css", false, 1); | 92 theme_source()->StartDataRequest("css/new_tab_theme.css", false, 1); |
| 92 EXPECT_EQ(theme_source()->result_request_id_, 1); | 93 EXPECT_EQ(theme_source()->result_request_id_, 1); |
| 93 EXPECT_NE(theme_source()->result_data_size_, empty_size); | 94 EXPECT_NE(theme_source()->result_data_size_, empty_size); |
| 94 | 95 |
| 95 theme_source()->StartDataRequest("css/newtab.css?pie", false, 3); | 96 theme_source()->StartDataRequest("css/new_tab_theme.css?pie", false, 3); |
| 96 EXPECT_EQ(theme_source()->result_request_id_, 3); | 97 EXPECT_EQ(theme_source()->result_request_id_, 3); |
| 97 EXPECT_NE(theme_source()->result_data_size_, empty_size); | 98 EXPECT_NE(theme_source()->result_data_size_, empty_size); |
| 98 | 99 |
| 99 // Check that we send NULL back when we can't find what we're looking for. | 100 // Check that we send NULL back when we can't find what we're looking for. |
| 100 theme_source()->StartDataRequest("css/WRONGURL", false, 7); | 101 theme_source()->StartDataRequest("css/WRONGURL", false, 7); |
| 101 EXPECT_EQ(theme_source()->result_request_id_, 7); | 102 EXPECT_EQ(theme_source()->result_request_id_, 7); |
| 102 EXPECT_EQ(theme_source()->result_data_size_, empty_size); | 103 EXPECT_EQ(theme_source()->result_data_size_, empty_size); |
| 103 } | 104 } |
| OLD | NEW |