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

Side by Side Diff: chrome/browser/image_decoder_browsertest.cc

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments #12 Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/image_decoder.h" 5 #include "chrome/browser/image_decoder.h"
6 6
7 #include "chrome/grit/generated_resources.h" 7 #include "chrome/grit/generated_resources.h"
8 #include "chrome/test/base/in_process_browser_test.h" 8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "content/public/browser/browser_child_process_observer.h" 9 #include "content/public/browser/browser_child_process_observer.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecode) { 140 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecode) {
141 scoped_refptr<content::MessageLoopRunner> runner = 141 scoped_refptr<content::MessageLoopRunner> runner =
142 new content::MessageLoopRunner; 142 new content::MessageLoopRunner;
143 TestImageRequest test_request(runner->QuitClosure()); 143 TestImageRequest test_request(runner->QuitClosure());
144 ImageDecoder::Start(&test_request, GetValidPngString()); 144 ImageDecoder::Start(&test_request, GetValidPngString());
145 runner->Run(); 145 runner->Run();
146 EXPECT_TRUE(test_request.decode_succeeded()); 146 EXPECT_TRUE(test_request.decode_succeeded());
147 } 147 }
148 148
149 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecodeFile) {
150 scoped_refptr<content::MessageLoopRunner> runner =
151 new content::MessageLoopRunner;
152 TestImageRequest test_request(runner->QuitClosure());
153 ImageDecoder::StartByFilePath(
154 &test_request,
155 base::FilePath(
156 FILE_PATH_LITERAL("chrome/test/data/image_decoding/droids.jpg")));
157 runner->Run();
158 EXPECT_TRUE(test_request.decode_succeeded());
159 }
160
149 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndDestroy) { 161 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndDestroy) {
150 scoped_refptr<content::MessageLoopRunner> runner = 162 scoped_refptr<content::MessageLoopRunner> runner =
151 new content::MessageLoopRunner; 163 new content::MessageLoopRunner;
152 scoped_ptr<TestImageRequest> test_request( 164 scoped_ptr<TestImageRequest> test_request(
153 new TestImageRequest(runner->QuitClosure())); 165 new TestImageRequest(runner->QuitClosure()));
154 ImageDecoder::Start(test_request.get(), std::string()); 166 ImageDecoder::Start(test_request.get(), std::string());
155 test_request.reset(); 167 test_request.reset();
156 runner->Run(); 168 runner->Run();
157 } 169 }
158 170
159 // Killing the utility process counts as a crash. Thus the request fails. 171 // Killing the utility process counts as a crash. Thus the request fails.
160 // If ImageDecoder did not handle the crash properly, the request never finishes 172 // If ImageDecoder did not handle the crash properly, the request never finishes
161 // and this test would hang. 173 // and this test would hang.
162 // Note: This test is inherently racy because KillProcessObserver lives on the 174 // Note: This test is inherently racy because KillProcessObserver lives on the
163 // UI thread but ImageDecoder does its work mainly on the IO thread. So the test 175 // UI thread but ImageDecoder does its work mainly on the IO thread. So the test
164 // checks for both possible valid outcomes. 176 // checks for both possible valid outcomes.
165 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndKillProcess) { 177 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndKillProcess) {
166 KillProcessObserver observer; 178 KillProcessObserver observer;
167 scoped_refptr<content::MessageLoopRunner> runner = 179 scoped_refptr<content::MessageLoopRunner> runner =
168 new content::MessageLoopRunner; 180 new content::MessageLoopRunner;
169 TestImageRequest test_request(runner->QuitClosure()); 181 TestImageRequest test_request(runner->QuitClosure());
170 ImageDecoder::Start(&test_request, GetValidPngString()); 182 ImageDecoder::Start(&test_request, GetValidPngString());
171 runner->Run(); 183 runner->Run();
172 if (!test_request.decode_succeeded()) { 184 if (!test_request.decode_succeeded()) {
173 // The UI thread won the race. Make sure the utility process did get killed. 185 // The UI thread won the race. Make sure the utility process did get killed.
174 EXPECT_TRUE(observer.did_kill()); 186 EXPECT_TRUE(observer.did_kill());
175 } 187 }
176 // Else the IO thread won the race and the image got decoded. Oh well. 188 // Else the IO thread won the race and the image got decoded. Oh well.
177 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698