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

Side by Side Diff: content/browser/gamepad/gamepad_provider_unittest.cc

Issue 780713002: Fix remaining WeakPtrFactory ordering problems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years 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 (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/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "content/browser/gamepad/gamepad_data_fetcher.h" 7 #include "content/browser/gamepad/gamepad_data_fetcher.h"
8 #include "content/browser/gamepad/gamepad_provider.h" 8 #include "content/browser/gamepad/gamepad_provider.h"
9 #include "content/browser/gamepad/gamepad_test_helpers.h" 9 #include "content/browser/gamepad/gamepad_test_helpers.h"
10 #include "content/common/gamepad_hardware_buffer.h" 10 #include "content/common/gamepad_hardware_buffer.h"
11 #include "content/common/gamepad_messages.h" 11 #include "content/common/gamepad_messages.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 using blink::WebGamepads; 18 using blink::WebGamepads;
19 19
20 // Helper class to generate and record user gesture callbacks. 20 // Helper class to generate and record user gesture callbacks.
21 class UserGestureListener { 21 class UserGestureListener {
22 public: 22 public:
23 UserGestureListener() 23 UserGestureListener()
24 : weak_factory_(this), 24 : has_user_gesture_(false),
25 has_user_gesture_(false) { 25 weak_factory_(this) {
26 } 26 }
27 27
28 base::Closure GetClosure() { 28 base::Closure GetClosure() {
29 return base::Bind(&UserGestureListener::GotUserGesture, 29 return base::Bind(&UserGestureListener::GotUserGesture,
30 weak_factory_.GetWeakPtr()); 30 weak_factory_.GetWeakPtr());
31 } 31 }
32 32
33 bool has_user_gesture() const { return has_user_gesture_; } 33 bool has_user_gesture() const { return has_user_gesture_; }
34 34
35 private: 35 private:
36 void GotUserGesture() { 36 void GotUserGesture() {
37 has_user_gesture_ = true; 37 has_user_gesture_ = true;
38 } 38 }
39 39
40 bool has_user_gesture_;
40 base::WeakPtrFactory<UserGestureListener> weak_factory_; 41 base::WeakPtrFactory<UserGestureListener> weak_factory_;
41 bool has_user_gesture_;
42 }; 42 };
43 43
44 // Main test fixture 44 // Main test fixture
45 class GamepadProviderTest : public testing::Test, public GamepadTestHelper { 45 class GamepadProviderTest : public testing::Test, public GamepadTestHelper {
46 public: 46 public:
47 GamepadProvider* CreateProvider(const WebGamepads& test_data) { 47 GamepadProvider* CreateProvider(const WebGamepads& test_data) {
48 mock_data_fetcher_ = new MockGamepadDataFetcher(test_data); 48 mock_data_fetcher_ = new MockGamepadDataFetcher(test_data);
49 provider_.reset(new GamepadProvider( 49 provider_.reset(new GamepadProvider(
50 scoped_ptr<GamepadDataFetcher>(mock_data_fetcher_))); 50 scoped_ptr<GamepadDataFetcher>(mock_data_fetcher_)));
51 return provider_.get(); 51 return provider_.get();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); 143 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
144 144
145 // It should have issued our callback. 145 // It should have issued our callback.
146 message_loop().RunUntilIdle(); 146 message_loop().RunUntilIdle();
147 EXPECT_TRUE(listener.has_user_gesture()); 147 EXPECT_TRUE(listener.has_user_gesture());
148 } 148 }
149 149
150 } // namespace 150 } // namespace
151 151
152 } // namespace content 152 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/obfuscated_file_util_unittest.cc ('k') | content/browser/renderer_host/p2p/socket_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698