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

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

Issue 1067593005: Fix race conditions in ImageDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use TestBrowserThreadBundle, cleanup tests Created 5 years, 8 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
« no previous file with comments | « chrome/browser/image_decoder.cc ('k') | chrome/browser/image_holder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/image_decoder.h"
6
7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/test/test_utils.h"
10
11 using content::BrowserThread;
12
13 namespace {
14
15 class TestImageRequest : public ImageDecoder::ImageRequest {
16 public:
17 explicit TestImageRequest(const base::Closure& quit_closure)
18 : quit_closure_(quit_closure),
19 quit_called_(false) {
20 }
21
22 ~TestImageRequest() override {
23 if (!quit_called_) {
24 quit_closure_.Run();
25 }
26 }
27
28 private:
29 void OnImageDecoded(const SkBitmap& decoded_image) override {
30 Quit();
31 }
32
33 void OnDecodeImageFailed() override {
34 Quit();
35 }
36
37 void Quit() {
38 EXPECT_FALSE(quit_called_);
39 quit_called_ = true;
40 quit_closure_.Run();
41 }
42
43 base::Closure quit_closure_;
44 bool quit_called_;
45
46 DISALLOW_COPY_AND_ASSIGN(TestImageRequest);
47 };
48
49 } // namespace
50
51 class ImageDecoderBrowserTest : public InProcessBrowserTest {
52 };
53
54 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, Basic) {
55 scoped_refptr<content::MessageLoopRunner> runner =
56 new content::MessageLoopRunner;
57 TestImageRequest test_request(runner->QuitClosure());
58 ImageDecoder::Start(&test_request, std::string());
59 runner->Run();
60 }
61
62 IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndDestroy) {
63 scoped_refptr<content::MessageLoopRunner> runner =
64 new content::MessageLoopRunner;
65 scoped_ptr<TestImageRequest> test_request(
66 new TestImageRequest(runner->QuitClosure()));
67 ImageDecoder::Start(test_request.get(), std::string());
68 test_request.reset();
69 runner->Run();
70 }
OLDNEW
« no previous file with comments | « chrome/browser/image_decoder.cc ('k') | chrome/browser/image_holder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698