Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc

Issue 159891: Make the DOMUIThemeSource load and pass through a PNG, rather than relying on... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.cc ('k') | views/widget/default_theme_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gfx/png_encoder.h" 5 #include "base/gfx/png_encoder.h"
6 #include "chrome/browser/browser_theme_provider.h" 6 #include "chrome/browser/browser_theme_provider.h"
7 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" 7 #include "chrome/browser/dom_ui/dom_ui_theme_source.h"
8 #include "chrome/browser/profile.h" 8 #include "chrome/browser/profile.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/testing_profile.h" 10 #include "chrome/test/testing_profile.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 // A mock ThemeSource (so we can override SendResponse to get at its data). 14 // A mock ThemeSource (so we can override SendResponse to get at its data).
15 class MockThemeSource : public DOMUIThemeSource { 15 class MockThemeSource : public DOMUIThemeSource {
16 public: 16 public:
17 explicit MockThemeSource(Profile* profile) 17 explicit MockThemeSource(Profile* profile)
18 : DOMUIThemeSource(profile), 18 : DOMUIThemeSource(profile),
19 result_request_id_(-1), 19 result_request_id_(-1),
20 result_data_size_(0) { 20 result_data_size_(0) {
21 } 21 }
22 22
23 virtual void SendResponse(int request_id, RefCountedBytes* data) { 23 virtual void SendResponse(int request_id, RefCountedBytes* data) {
24 result_data_size_ = data ? data->data.size() : 0; 24 result_data_size_ = data ? data->data.size() : 0;
25 result_request_id_ = request_id; 25 result_request_id_ = request_id;
26 } 26 }
27 27
28 int result_request_id_; 28 int result_request_id_;
29 size_t result_data_size_; 29 size_t result_data_size_;
30 }; 30 };
(...skipping 18 matching lines...) Expand all
49 scoped_refptr<MockThemeSource> theme_source_; 49 scoped_refptr<MockThemeSource> theme_source_;
50 }; 50 };
51 51
52 TEST_F(DOMUISourcesTest, ThemeSourceMimeTypes) { 52 TEST_F(DOMUISourcesTest, ThemeSourceMimeTypes) {
53 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css"); 53 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css");
54 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css"); 54 EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css");
55 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png"); 55 EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png");
56 } 56 }
57 57
58 TEST_F(DOMUISourcesTest, ThemeSourceImages) { 58 TEST_F(DOMUISourcesTest, ThemeSourceImages) {
59 // Our test data. Rather than comparing the data itself, we just compare 59 // We used to PNGEncode the images ourselves, but encoder differences
60 // its size. 60 // invalidated that. We now just check that the image exists.
61 SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed(
62 IDR_THEME_FRAME_INCOGNITO);
63 std::vector<unsigned char> png_bytes;
64 PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes);
65
66 theme_source()->StartDataRequest("theme_frame_incognito", 1); 61 theme_source()->StartDataRequest("theme_frame_incognito", 1);
62 size_t min = 0;
67 EXPECT_EQ(theme_source()->result_request_id_, 1); 63 EXPECT_EQ(theme_source()->result_request_id_, 1);
68 EXPECT_EQ(theme_source()->result_data_size_, png_bytes.size()); 64 EXPECT_GT(theme_source()->result_data_size_, min);
69 65
70 theme_source()->StartDataRequest("theme_toolbar", 2); 66 theme_source()->StartDataRequest("theme_toolbar", 2);
71 EXPECT_EQ(theme_source()->result_request_id_, 2); 67 EXPECT_EQ(theme_source()->result_request_id_, 2);
72 EXPECT_NE(theme_source()->result_data_size_, png_bytes.size()); 68 EXPECT_GT(theme_source()->result_data_size_, min);
73 } 69 }
74 70
75 TEST_F(DOMUISourcesTest, ThemeSourceCSS) { 71 TEST_F(DOMUISourcesTest, ThemeSourceCSS) {
76 // Generating the test data for the NTP CSS would just involve copying the 72 // Generating the test data for the NTP CSS would just involve copying the
77 // method, or being super brittle and hard-coding the result (requiring 73 // method, or being super brittle and hard-coding the result (requiring
78 // an update to the unittest every time the CSS template changes), so we 74 // an update to the unittest every time the CSS template changes), so we
79 // just check for a successful request and data that is non-null. 75 // just check for a successful request and data that is non-null.
80 size_t empty_size = 0; 76 size_t empty_size = 0;
81 77
82 theme_source()->StartDataRequest("css/newtab.css", 1); 78 theme_source()->StartDataRequest("css/newtab.css", 1);
83 EXPECT_EQ(theme_source()->result_request_id_, 1); 79 EXPECT_EQ(theme_source()->result_request_id_, 1);
84 EXPECT_NE(theme_source()->result_data_size_, empty_size); 80 EXPECT_NE(theme_source()->result_data_size_, empty_size);
85 81
86 theme_source()->StartDataRequest("css/newtab.css?pie", 3); 82 theme_source()->StartDataRequest("css/newtab.css?pie", 3);
87 EXPECT_EQ(theme_source()->result_request_id_, 3); 83 EXPECT_EQ(theme_source()->result_request_id_, 3);
88 EXPECT_NE(theme_source()->result_data_size_, empty_size); 84 EXPECT_NE(theme_source()->result_data_size_, empty_size);
89 85
90 // Check that we send NULL back when we can't find what we're looking for. 86 // Check that we send NULL back when we can't find what we're looking for.
91 theme_source()->StartDataRequest("css/WRONGURL", 7); 87 theme_source()->StartDataRequest("css/WRONGURL", 7);
92 EXPECT_EQ(theme_source()->result_request_id_, 7); 88 EXPECT_EQ(theme_source()->result_request_id_, 7);
93 EXPECT_EQ(theme_source()->result_data_size_, empty_size); 89 EXPECT_EQ(theme_source()->result_data_size_, empty_size);
94 } 90 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.cc ('k') | views/widget/default_theme_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698