Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ | 5 #ifndef BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ |
| 6 #define BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ | 6 #define BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/synchronization/waitable_event.h" | |
| 10 #include "content/public/test/browser_test_base.h" | 11 #include "content/public/test/browser_test_base.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 class RunLoop; | 14 class RunLoop; |
| 14 } | 15 } |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class WebContents; | 18 class WebContents; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace blimp { | 21 namespace blimp { |
| 21 namespace client { | 22 namespace client { |
| 22 struct Assignment; | 23 struct Assignment; |
| 23 } // namespace client | 24 } // namespace client |
| 24 | 25 |
| 25 namespace engine { | 26 namespace engine { |
| 26 class BlimpEngineSession; | 27 class BlimpEngineSession; |
| 27 } // namespace engine | 28 } // namespace engine |
| 28 | 29 |
| 29 // Base class for tests which require a full instance of the Blimp engine. | 30 // Base class for tests which require a full instance of the Blimp engine. |
| 30 class BlimpBrowserTest : public content::BrowserTestBase { | 31 class BlimpBrowserTest : public content::BrowserTestBase { |
| 31 public: | 32 public: |
| 32 // Notify that an asynchronous test is now complete and the test runner should | 33 // Notify that an asynchronous test is now complete and the test runner should |
| 33 // exit. | 34 // exit. |
| 34 void QuitRunLoop(); | 35 void QuitRunLoop(); |
| 35 | 36 |
| 37 // Tells RunUntilCompletion() to break and discontinue processing UI & IO | |
| 38 // thread MessageLoops. | |
| 39 void SignalCompletion(); | |
| 40 | |
| 36 protected: | 41 protected: |
| 37 BlimpBrowserTest(); | 42 BlimpBrowserTest(); |
| 38 ~BlimpBrowserTest() override; | 43 ~BlimpBrowserTest() override; |
| 39 | 44 |
| 40 // Run an asynchronous test in a nested run loop. The caller should call | 45 // Processes tasks in the UI and IO thread until SignalCompletion() is |
| 41 // QuitRunLoop() to notify that the test should finish. | 46 // called. |
| 42 void RunUntilQuit(); | 47 void RunUntilCompletion(); |
| 43 | 48 |
| 44 engine::BlimpEngineSession* GetEngineSession(); | 49 engine::BlimpEngineSession* GetEngineSession(); |
| 45 | 50 |
| 46 client::Assignment GetAssignment(); | 51 client::Assignment GetAssignment(); |
| 47 | 52 |
| 48 // testing::Test implementation. | 53 // testing::Test implementation. |
| 49 void SetUp() override; | 54 void SetUp() override; |
| 50 | 55 |
| 51 // content::BrowserTestBase implementation. | 56 // content::BrowserTestBase implementation. |
| 52 void RunTestOnMainThreadLoop() override; | 57 void RunTestOnMainThreadLoop() override; |
| 58 void SetUpCommandLine(base::CommandLine* command_line) override; | |
| 53 void SetUpOnMainThread() override; | 59 void SetUpOnMainThread() override; |
| 54 void TearDownOnMainThread() override; | 60 void TearDownOnMainThread() override; |
| 55 void SetUpCommandLine(base::CommandLine* command_line) override; | |
| 56 | 61 |
| 57 private: | 62 private: |
| 58 void OnGetEnginePort(uint16_t port); | 63 // Stores the port number, which was retrieved asynchronously from |
| 64 // BlimpEngineSession. | |
| 65 void set_engine_port(uint16_t port) { engine_port_ = port; } | |
|
Wez
2016/08/19 19:15:50
nit: This comment doesn't make clear why we need t
Kevin M
2016/08/19 21:43:33
Done.
| |
| 59 | 66 |
| 60 uint16_t engine_port_; | 67 uint16_t engine_port_; |
| 61 std::unique_ptr<base::RunLoop> run_loop_; | 68 |
| 69 // Used to signal the completion of asynchronous processing to | |
| 70 // RunUntilCompletion(). | |
| 71 base::WaitableEvent completion_event_; | |
| 62 | 72 |
| 63 DISALLOW_COPY_AND_ASSIGN(BlimpBrowserTest); | 73 DISALLOW_COPY_AND_ASSIGN(BlimpBrowserTest); |
| 64 }; | 74 }; |
| 65 | 75 |
| 66 } // namespace blimp | 76 } // namespace blimp |
| 67 | 77 |
| 68 #endif // BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ | 78 #endif // BLIMP_ENGINE_BROWSER_TESTS_BLIMP_BROWSER_TEST_H_ |
| OLD | NEW |