OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/search/suggestions/image_fetcher_impl.h" | 5 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 class TestImageFetcherDelegate : public ImageFetcherDelegate { | 32 class TestImageFetcherDelegate : public ImageFetcherDelegate { |
33 public: | 33 public: |
34 TestImageFetcherDelegate() | 34 TestImageFetcherDelegate() |
35 : num_delegate_valid_called_(0), | 35 : num_delegate_valid_called_(0), |
36 num_delegate_null_called_(0) {} | 36 num_delegate_null_called_(0) {} |
37 virtual ~TestImageFetcherDelegate() {}; | 37 virtual ~TestImageFetcherDelegate() {}; |
38 | 38 |
39 // Perform additional tasks when an image has been fetched. | 39 // Perform additional tasks when an image has been fetched. |
40 virtual void OnImageFetched(const GURL& url, const SkBitmap* bitmap) | 40 virtual void OnImageFetched(const GURL& url, const SkBitmap* bitmap) |
41 OVERRIDE { | 41 override { |
42 if (bitmap) { | 42 if (bitmap) { |
43 num_delegate_valid_called_++; | 43 num_delegate_valid_called_++; |
44 } else { | 44 } else { |
45 num_delegate_null_called_++; | 45 num_delegate_null_called_++; |
46 } | 46 } |
47 }; | 47 }; |
48 | 48 |
49 int num_delegate_valid_called() { return num_delegate_valid_called_; } | 49 int num_delegate_valid_called() { return num_delegate_valid_called_; } |
50 int num_delegate_null_called() { return num_delegate_null_called_; } | 50 int num_delegate_null_called() { return num_delegate_null_called_; } |
51 | 51 |
52 private: | 52 private: |
53 int num_delegate_valid_called_; | 53 int num_delegate_valid_called_; |
54 int num_delegate_null_called_; | 54 int num_delegate_null_called_; |
55 }; | 55 }; |
56 | 56 |
57 } // end namespace | 57 } // end namespace |
58 | 58 |
59 class ImageFetcherImplBrowserTest : public InProcessBrowserTest { | 59 class ImageFetcherImplBrowserTest : public InProcessBrowserTest { |
60 protected: | 60 protected: |
61 ImageFetcherImplBrowserTest() | 61 ImageFetcherImplBrowserTest() |
62 : num_callback_valid_called_(0), | 62 : num_callback_valid_called_(0), |
63 num_callback_null_called_(0), | 63 num_callback_null_called_(0), |
64 test_server_(net::SpawnedTestServer::TYPE_HTTP, | 64 test_server_(net::SpawnedTestServer::TYPE_HTTP, |
65 net::SpawnedTestServer::kLocalhost, | 65 net::SpawnedTestServer::kLocalhost, |
66 base::FilePath(kDocRoot)) {} | 66 base::FilePath(kDocRoot)) {} |
67 | 67 |
68 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 68 virtual void SetUpInProcessBrowserTestFixture() override { |
69 ASSERT_TRUE(test_server_.Start()); | 69 ASSERT_TRUE(test_server_.Start()); |
70 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 70 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
71 } | 71 } |
72 | 72 |
73 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 73 virtual void TearDownInProcessBrowserTestFixture() override { |
74 test_server_.Stop(); | 74 test_server_.Stop(); |
75 } | 75 } |
76 | 76 |
77 ImageFetcherImpl* CreateImageFetcher() { | 77 ImageFetcherImpl* CreateImageFetcher() { |
78 ImageFetcherImpl* fetcher = | 78 ImageFetcherImpl* fetcher = |
79 new ImageFetcherImpl(browser()->profile()->GetRequestContext()); | 79 new ImageFetcherImpl(browser()->profile()->GetRequestContext()); |
80 fetcher->SetImageFetcherDelegate(&delegate_); | 80 fetcher->SetImageFetcherDelegate(&delegate_); |
81 return fetcher; | 81 return fetcher; |
82 } | 82 } |
83 | 83 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 GURL invalid_image_url(test_server_.GetURL(kInvalidImagePath).spec()); | 140 GURL invalid_image_url(test_server_.GetURL(kInvalidImagePath).spec()); |
141 StartOrQueueNetworkRequestHelper(invalid_image_url); | 141 StartOrQueueNetworkRequestHelper(invalid_image_url); |
142 | 142 |
143 EXPECT_EQ(0, num_callback_valid_called_); | 143 EXPECT_EQ(0, num_callback_valid_called_); |
144 EXPECT_EQ(1, num_callback_null_called_); | 144 EXPECT_EQ(1, num_callback_null_called_); |
145 EXPECT_EQ(0, delegate_.num_delegate_valid_called()); | 145 EXPECT_EQ(0, delegate_.num_delegate_valid_called()); |
146 EXPECT_EQ(1, delegate_.num_delegate_null_called()); | 146 EXPECT_EQ(1, delegate_.num_delegate_null_called()); |
147 } | 147 } |
148 | 148 |
149 } // namespace suggestions | 149 } // namespace suggestions |
OLD | NEW |