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

Side by Side Diff: chrome/browser/search/suggestions/image_fetcher_impl_browsertest.cc

Issue 2794343002: Network traffic annotation added to image_data_fetcher. (Closed)
Patch Set: Annotation updated. Created 3 years, 7 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
OLDNEW
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 "components/image_fetcher/core/image_fetcher_impl.h" 5 #include "components/image_fetcher/core/image_fetcher_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 15 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "components/image_fetcher/core/image_fetcher_delegate.h" 18 #include "components/image_fetcher/core/image_fetcher_delegate.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h" 19 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 using image_fetcher::ImageFetcher; 25 using image_fetcher::ImageFetcher;
25 using image_fetcher::ImageFetcherImpl; 26 using image_fetcher::ImageFetcherImpl;
26 using image_fetcher::ImageFetcherDelegate; 27 using image_fetcher::ImageFetcherDelegate;
27 28
28 namespace suggestions { 29 namespace suggestions {
29 30
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 test_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 70 test_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
70 } 71 }
71 72
72 void SetUpInProcessBrowserTestFixture() override { 73 void SetUpInProcessBrowserTestFixture() override {
73 ASSERT_TRUE(test_server_.Start()); 74 ASSERT_TRUE(test_server_.Start());
74 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 75 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
75 } 76 }
76 77
77 ImageFetcherImpl* CreateImageFetcher() { 78 ImageFetcherImpl* CreateImageFetcher() {
78 ImageFetcherImpl* fetcher = 79 ImageFetcherImpl* fetcher =
79 new ImageFetcherImpl( 80 new ImageFetcherImpl(base::MakeUnique<suggestions::ImageDecoderImpl>(),
80 base::MakeUnique<suggestions::ImageDecoderImpl>(), 81 browser()->profile()->GetRequestContext());
81 browser()->profile()->GetRequestContext());
82 fetcher->SetImageFetcherDelegate(&delegate_); 82 fetcher->SetImageFetcherDelegate(&delegate_);
83 return fetcher; 83 return fetcher;
84 } 84 }
85 85
86 void OnImageAvailable(base::RunLoop* loop, 86 void OnImageAvailable(base::RunLoop* loop,
87 const std::string& id, 87 const std::string& id,
88 const gfx::Image& image, 88 const gfx::Image& image,
89 const image_fetcher::RequestMetadata& metadata) { 89 const image_fetcher::RequestMetadata& metadata) {
90 if (!image.IsEmpty()) { 90 if (!image.IsEmpty()) {
91 num_callback_valid_called_++; 91 num_callback_valid_called_++;
92 } else { 92 } else {
93 num_callback_null_called_++; 93 num_callback_null_called_++;
94 } 94 }
95 loop->Quit(); 95 loop->Quit();
96 } 96 }
97 97
98 void StartOrQueueNetworkRequestHelper(const GURL& image_url) { 98 void StartOrQueueNetworkRequestHelper(const GURL& image_url) {
99 std::unique_ptr<ImageFetcherImpl> image_fetcher_(CreateImageFetcher()); 99 std::unique_ptr<ImageFetcherImpl> image_fetcher_(CreateImageFetcher());
100 100
101 base::RunLoop run_loop; 101 base::RunLoop run_loop;
102 image_fetcher_->StartOrQueueNetworkRequest( 102 image_fetcher_->StartOrQueueNetworkRequest(
103 kTestUrl, 103 kTestUrl, image_url,
104 image_url,
105 base::Bind(&ImageFetcherImplBrowserTest::OnImageAvailable, 104 base::Bind(&ImageFetcherImplBrowserTest::OnImageAvailable,
106 base::Unretained(this), &run_loop)); 105 base::Unretained(this), &run_loop),
106 TRAFFIC_ANNOTATION_FOR_TESTS);
107 run_loop.Run(); 107 run_loop.Run();
108 } 108 }
109 109
110 int num_callback_valid_called_; 110 int num_callback_valid_called_;
111 int num_callback_null_called_; 111 int num_callback_null_called_;
112 112
113 net::EmbeddedTestServer test_server_; 113 net::EmbeddedTestServer test_server_;
114 TestImageFetcherDelegate delegate_; 114 TestImageFetcherDelegate delegate_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImplBrowserTest); 116 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImplBrowserTest);
(...skipping 26 matching lines...) Expand all
143 GURL invalid_image_url(test_server_.GetURL(kInvalidImagePath).spec()); 143 GURL invalid_image_url(test_server_.GetURL(kInvalidImagePath).spec());
144 StartOrQueueNetworkRequestHelper(invalid_image_url); 144 StartOrQueueNetworkRequestHelper(invalid_image_url);
145 145
146 EXPECT_EQ(0, num_callback_valid_called_); 146 EXPECT_EQ(0, num_callback_valid_called_);
147 EXPECT_EQ(1, num_callback_null_called_); 147 EXPECT_EQ(1, num_callback_null_called_);
148 EXPECT_EQ(0, delegate_.num_delegate_valid_called()); 148 EXPECT_EQ(0, delegate_.num_delegate_valid_called());
149 EXPECT_EQ(1, delegate_.num_delegate_null_called()); 149 EXPECT_EQ(1, delegate_.num_delegate_null_called());
150 } 150 }
151 151
152 } // namespace suggestions 152 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698