| Index: chrome/browser/ui/webui/theme_source_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/ui/webui/theme_source_unittest.cc (revision 176942)
|
| +++ chrome/browser/ui/webui/theme_source_unittest.cc (working copy)
|
| @@ -2,10 +2,10 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/bind.h"
|
| #include "base/memory/ref_counted_memory.h"
|
| #include "base/message_loop.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
|
| #include "chrome/browser/ui/webui/theme_source.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| @@ -15,55 +15,46 @@
|
|
|
| using content::BrowserThread;
|
|
|
| -// A mock URLDataSource (so we can override SendResponse to get at its data).
|
| -class MockURLDataSource : public URLDataSource {
|
| +class WebUISourcesTest : public testing::Test {
|
| public:
|
| - explicit MockURLDataSource(content::URLDataSourceDelegate* delegate)
|
| - : URLDataSource(std::string(), delegate),
|
| - result_request_id_(-1), result_data_size_(0) {
|
| - }
|
| + WebUISourcesTest()
|
| + : result_data_size_(0),
|
| + ui_thread_(BrowserThread::UI, MessageLoop::current()) {}
|
|
|
| - virtual void SendResponse(int request_id,
|
| - base::RefCountedMemory* data) OVERRIDE {
|
| - result_data_size_ = data ? data->size() : 0;
|
| - result_request_id_ = request_id;
|
| + TestingProfile* profile() const { return profile_.get(); }
|
| + ThemeSource* theme_source() const { return theme_source_.get(); }
|
| + size_t result_data_size() const { return result_data_size_; }
|
| +
|
| + void StartDataRequest(const std::string& source, bool is_incognito) {
|
| + theme_source()->StartDataRequest(source, is_incognito, callback_);
|
| }
|
|
|
| - int result_request_id_;
|
| size_t result_data_size_;
|
|
|
| private:
|
| - ~MockURLDataSource() {}
|
| -};
|
| -
|
| -class WebUISourcesTest : public testing::Test {
|
| - public:
|
| - WebUISourcesTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}
|
| -
|
| - TestingProfile* profile() const { return profile_.get(); }
|
| - ThemeSource* theme_source() const { return theme_source_; }
|
| - MockURLDataSource* data_source() const { return data_source_.get(); }
|
| -
|
| - private:
|
| virtual void SetUp() {
|
| profile_.reset(new TestingProfile());
|
| - theme_source_ = new ThemeSource(profile_.get());
|
| - data_source_ = new MockURLDataSource(theme_source_);
|
| - theme_source_->set_url_data_source_for_testing(data_source_.get());
|
| + theme_source_.reset(new ThemeSource(profile_.get()));
|
| + callback_ = base::Bind(&WebUISourcesTest::SendResponse,
|
| + base::Unretained(this));
|
| }
|
|
|
| virtual void TearDown() {
|
| - theme_source_ = NULL;
|
| - data_source_ = NULL;
|
| - profile_.reset(NULL);
|
| + theme_source_.reset();
|
| + profile_.reset();
|
| }
|
|
|
| + void SendResponse(base::RefCountedMemory* data) {
|
| + result_data_size_ = data ? data->size() : 0;
|
| + }
|
| +
|
| + content::URLDataSource::GotDataCallback callback_;
|
| +
|
| MessageLoop loop_;
|
| content::TestBrowserThread ui_thread_;
|
|
|
| scoped_ptr<TestingProfile> profile_;
|
| - scoped_refptr<MockURLDataSource> data_source_;
|
| - ThemeSource* theme_source_;
|
| + scoped_ptr<ThemeSource> theme_source_;
|
| };
|
|
|
| TEST_F(WebUISourcesTest, ThemeSourceMimeTypes) {
|
| @@ -76,14 +67,12 @@
|
| TEST_F(WebUISourcesTest, ThemeSourceImages) {
|
| // We used to PNGEncode the images ourselves, but encoder differences
|
| // invalidated that. We now just check that the image exists.
|
| - theme_source()->StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true, 1);
|
| + StartDataRequest("IDR_THEME_FRAME_INCOGNITO", true);
|
| size_t min = 0;
|
| - EXPECT_EQ(data_source()->result_request_id_, 1);
|
| - EXPECT_GT(data_source()->result_data_size_, min);
|
| + EXPECT_GT(result_data_size_, min);
|
|
|
| - theme_source()->StartDataRequest("IDR_THEME_TOOLBAR", true, 2);
|
| - EXPECT_EQ(data_source()->result_request_id_, 2);
|
| - EXPECT_GT(data_source()->result_data_size_, min);
|
| + StartDataRequest("IDR_THEME_TOOLBAR", true);
|
| + EXPECT_GT(result_data_size_, min);
|
| }
|
|
|
| TEST_F(WebUISourcesTest, ThemeSourceCSS) {
|
| @@ -95,16 +84,13 @@
|
| // just check for a successful request and data that is non-null.
|
| size_t empty_size = 0;
|
|
|
| - theme_source()->StartDataRequest("css/new_tab_theme.css", false, 1);
|
| - EXPECT_EQ(data_source()->result_request_id_, 1);
|
| - EXPECT_NE(data_source()->result_data_size_, empty_size);
|
| + StartDataRequest("css/new_tab_theme.css", false);
|
| + EXPECT_NE(result_data_size_, empty_size);
|
|
|
| - theme_source()->StartDataRequest("css/new_tab_theme.css?pie", false, 3);
|
| - EXPECT_EQ(data_source()->result_request_id_, 3);
|
| - EXPECT_NE(data_source()->result_data_size_, empty_size);
|
| + StartDataRequest("css/new_tab_theme.css?pie", false);
|
| + EXPECT_NE(result_data_size_, empty_size);
|
|
|
| // Check that we send NULL back when we can't find what we're looking for.
|
| - theme_source()->StartDataRequest("css/WRONGURL", false, 7);
|
| - EXPECT_EQ(data_source()->result_request_id_, 7);
|
| - EXPECT_EQ(data_source()->result_data_size_, empty_size);
|
| + StartDataRequest("css/WRONGURL", false);
|
| + EXPECT_EQ(result_data_size_, empty_size);
|
| }
|
|
|