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/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/icon_manager.h" | 7 #include "chrome/browser/icon_manager.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/webui/fileicon_source.h" | 9 #include "chrome/browser/ui/webui/fileicon_source.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class TestFileIconSource : public FileIconSource { | 19 class TestFileIconSource : public FileIconSource { |
20 public: | 20 public: |
21 explicit TestFileIconSource() {} | 21 explicit TestFileIconSource() {} |
22 | 22 |
23 MOCK_METHOD4(FetchFileIcon, void(const FilePath& path, | 23 MOCK_METHOD4(FetchFileIcon, |
24 ui::ScaleFactor scale_factor, | 24 void(const FilePath& path, |
25 IconLoader::IconSize icon_size, | 25 ui::ScaleFactor scale_factor, |
26 int request_id)); | 26 IconLoader::IconSize icon_size, |
| 27 const content::URLDataSource::GotDataCallback& callback)); |
27 | 28 |
28 virtual ~TestFileIconSource() {} | 29 virtual ~TestFileIconSource() {} |
29 }; | 30 }; |
30 | 31 |
31 class FileIconSourceTest : public testing::Test { | 32 class FileIconSourceTest : public testing::Test { |
32 public: | 33 public: |
33 FileIconSourceTest() | 34 FileIconSourceTest() |
34 : loop_(MessageLoop::TYPE_UI), | 35 : loop_(MessageLoop::TYPE_UI), |
35 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 36 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
36 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} | 37 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 FILE_PATH_LITERAL("/foo/\xe0\xb6\x9a\xe0\xb6\xbb\xe0\xb7\x9d") | 103 FILE_PATH_LITERAL("/foo/\xe0\xb6\x9a\xe0\xb6\xbb\xe0\xb7\x9d") |
103 FILE_PATH_LITERAL("\xe0\xb6\xb8\xe0\xb7\x8a"), ui::SCALE_FACTOR_100P, | 104 FILE_PATH_LITERAL("\xe0\xb6\xb8\xe0\xb7\x8a"), ui::SCALE_FACTOR_100P, |
104 IconLoader::NORMAL }, | 105 IconLoader::NORMAL }, |
105 { "%2Ffoo%2Fbar", FILE_PATH_LITERAL("/foo/bar"), ui::SCALE_FACTOR_100P, | 106 { "%2Ffoo%2Fbar", FILE_PATH_LITERAL("/foo/bar"), ui::SCALE_FACTOR_100P, |
106 IconLoader::NORMAL }, | 107 IconLoader::NORMAL }, |
107 { "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("/baz (1).txt"), | 108 { "%2Fbaz%20(1).txt?iconsize=small", FILE_PATH_LITERAL("/baz (1).txt"), |
108 ui::SCALE_FACTOR_100P, IconLoader::SMALL }, | 109 ui::SCALE_FACTOR_100P, IconLoader::SMALL }, |
109 #endif | 110 #endif |
110 }; | 111 }; |
111 | 112 |
| 113 // Test that the callback is NULL. |
| 114 MATCHER(CallbackIsNull, "") { |
| 115 return arg.is_null(); |
| 116 } |
| 117 |
112 } // namespace | 118 } // namespace |
113 | 119 |
114 TEST_F(FileIconSourceTest, FileIconSource_Parse) { | 120 TEST_F(FileIconSourceTest, FileIconSource_Parse) { |
115 for (unsigned i = 0; i < arraysize(kBasicExpectations); i++) { | 121 for (unsigned i = 0; i < arraysize(kBasicExpectations); i++) { |
116 scoped_ptr<TestFileIconSource> source(CreateFileIconSource()); | 122 scoped_ptr<TestFileIconSource> source(CreateFileIconSource()); |
| 123 content::URLDataSource::GotDataCallback callback; |
117 EXPECT_CALL(*source.get(), | 124 EXPECT_CALL(*source.get(), |
118 FetchFileIcon(FilePath(kBasicExpectations[i].unescaped_path), | 125 FetchFileIcon(FilePath(kBasicExpectations[i].unescaped_path), |
119 kBasicExpectations[i].scale_factor, | 126 kBasicExpectations[i].scale_factor, |
120 kBasicExpectations[i].size, i)); | 127 kBasicExpectations[i].size, CallbackIsNull())); |
121 source->StartDataRequest(kBasicExpectations[i].request_path, false, i); | 128 source->StartDataRequest(kBasicExpectations[i].request_path, false, |
| 129 callback); |
122 } | 130 } |
123 } | 131 } |
OLD | NEW |