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 "chrome/browser/ui/webui/fileicon_source.h" |
5 #include "base/macros.h" | 6 #include "base/macros.h" |
6 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
7 #include "base/message_loop/message_loop.h" | |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/icon_manager.h" | 9 #include "chrome/browser/icon_manager.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/webui/fileicon_source.h" | |
12 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
13 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 using content::BrowserThread; | |
18 | |
19 namespace { | 16 namespace { |
20 | 17 |
21 class TestFileIconSource : public FileIconSource { | 18 class TestFileIconSource : public FileIconSource { |
22 public: | 19 public: |
23 TestFileIconSource() {} | 20 TestFileIconSource() {} |
24 | 21 |
25 MOCK_METHOD4(FetchFileIcon, | 22 MOCK_METHOD4(FetchFileIcon, |
26 void(const base::FilePath& path, | 23 void(const base::FilePath& path, |
27 float scale_factor, | 24 float scale_factor, |
28 IconLoader::IconSize icon_size, | 25 IconLoader::IconSize icon_size, |
29 const content::URLDataSource::GotDataCallback& callback)); | 26 const content::URLDataSource::GotDataCallback& callback)); |
30 | 27 |
31 virtual ~TestFileIconSource() {} | 28 virtual ~TestFileIconSource() {} |
32 }; | 29 }; |
33 | 30 |
34 class FileIconSourceTest : public testing::Test { | 31 class FileIconSourceTest : public testing::Test { |
35 public: | 32 public: |
36 FileIconSourceTest() | 33 FileIconSourceTest() = default; |
37 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | |
38 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} | |
39 | 34 |
40 static TestFileIconSource* CreateFileIconSource() { | 35 static TestFileIconSource* CreateFileIconSource() { |
41 return new TestFileIconSource(); | 36 return new TestFileIconSource(); |
42 } | 37 } |
43 | 38 |
44 private: | 39 private: |
45 base::MessageLoopForUI loop_; | 40 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
46 content::TestBrowserThread ui_thread_; | |
47 content::TestBrowserThread file_thread_; | |
48 }; | 41 }; |
49 | 42 |
50 const struct FetchFileIconExpectation { | 43 const struct FetchFileIconExpectation { |
51 const char* request_path; | 44 const char* request_path; |
52 const base::FilePath::CharType* unescaped_path; | 45 const base::FilePath::CharType* unescaped_path; |
53 float scale_factor; | 46 float scale_factor; |
54 IconLoader::IconSize size; | 47 IconLoader::IconSize size; |
55 } kBasicExpectations[] = { | 48 } kBasicExpectations[] = { |
56 { "foo?bar", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::NORMAL }, | 49 { "foo?bar", FILE_PATH_LITERAL("foo"), 1.0f, IconLoader::NORMAL }, |
57 { "foo?bar&scale=2x", FILE_PATH_LITERAL("foo"), 2.0f, IconLoader::NORMAL }, | 50 { "foo?bar&scale=2x", FILE_PATH_LITERAL("foo"), 2.0f, IconLoader::NORMAL }, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 FetchFileIcon( | 112 FetchFileIcon( |
120 base::FilePath(kBasicExpectations[i].unescaped_path), | 113 base::FilePath(kBasicExpectations[i].unescaped_path), |
121 kBasicExpectations[i].scale_factor, | 114 kBasicExpectations[i].scale_factor, |
122 kBasicExpectations[i].size, CallbackIsNull())); | 115 kBasicExpectations[i].size, CallbackIsNull())); |
123 source->StartDataRequest( | 116 source->StartDataRequest( |
124 kBasicExpectations[i].request_path, | 117 kBasicExpectations[i].request_path, |
125 content::ResourceRequestInfo::WebContentsGetter(), | 118 content::ResourceRequestInfo::WebContentsGetter(), |
126 callback); | 119 callback); |
127 } | 120 } |
128 } | 121 } |
OLD | NEW |