| Index: gpu/command_buffer/client/gles2_implementation_unittest.cc | 
| diff --git a/gpu/command_buffer/client/gles2_implementation_unittest.cc b/gpu/command_buffer/client/gles2_implementation_unittest.cc | 
| index 2dd4ae7cd9f0bace6744844dd0cfe35161726070..62d50f27a774ddd807d6b4eeb2c5ed75f8dc88ba 100644 | 
| --- a/gpu/command_buffer/client/gles2_implementation_unittest.cc | 
| +++ b/gpu/command_buffer/client/gles2_implementation_unittest.cc | 
| @@ -16,8 +16,11 @@ | 
|  | 
| #include <memory> | 
|  | 
| +#include "base/bind.h" | 
| #include "base/compiler_specific.h" | 
| #include "base/memory/ptr_util.h" | 
| +#include "base/test/test_mock_time_task_runner.h" | 
| +#include "base/threading/thread_task_runner_handle.h" | 
| #include "gpu/command_buffer/client/client_test_helper.h" | 
| #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 
| #include "gpu/command_buffer/client/program_info_manager.h" | 
| @@ -483,6 +486,8 @@ class GLES2ImplementationTest : public testing::Test { | 
| EXPECT_CALL(*gpu_control_, GetCapabilities()) | 
| .WillOnce(Return(capabilities)); | 
|  | 
| +      task_runner_ = make_scoped_refptr(new base::TestMockTimeTaskRunner()); | 
| + | 
| { | 
| InSequence sequence; | 
|  | 
| @@ -490,7 +495,7 @@ class GLES2ImplementationTest : public testing::Test { | 
| gl_.reset(new GLES2Implementation( | 
| helper_.get(), share_group, transfer_buffer_.get(), | 
| bind_generates_resource_client, lose_context_when_out_of_memory, | 
| -            support_client_side_arrays, gpu_control_.get(), nullptr)); | 
| +            support_client_side_arrays, gpu_control_.get(), task_runner_)); | 
| } | 
|  | 
| // The client should be set to something non-null. | 
| @@ -540,6 +545,7 @@ class GLES2ImplementationTest : public testing::Test { | 
| std::unique_ptr<GLES2CmdHelper> helper_; | 
| std::unique_ptr<MockTransferBuffer> transfer_buffer_; | 
| std::unique_ptr<GLES2Implementation> gl_; | 
| +    scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; | 
| CommandBufferEntry* commands_; | 
| int token_; | 
| }; | 
| @@ -626,6 +632,10 @@ class GLES2ImplementationTest : public testing::Test { | 
| return test_contexts_[0].command_buffer_.get(); | 
| } | 
|  | 
| +  base::TestMockTimeTaskRunner* task_runner() const { | 
| +    return test_contexts_[0].task_runner_.get(); | 
| +  } | 
| + | 
| int GetNextToken() { return test_contexts_[0].GetNextToken(); } | 
|  | 
| const void* GetPut() { | 
| @@ -4648,6 +4658,43 @@ TEST_F(GLES2ImplementationTest, TrimResources) { | 
| } | 
| } | 
|  | 
| +TEST_F(GLES2ImplementationTest, ClientBusyBasic) { | 
| +  bool signaled = false; | 
| +  gl_->SetIdleCallback( | 
| +      base::Bind([](bool* signaled) { *signaled = true; }, &signaled)); | 
| +  auto busy = gl_->ClientBecameBusy(); | 
| +  gl_->ClientBecameNotBusy(std::move(busy)); | 
| + | 
| +  task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 
| +  EXPECT_TRUE(signaled); | 
| +} | 
| + | 
| +TEST_F(GLES2ImplementationTest, ClientBusyCancelled) { | 
| +  auto runner = make_scoped_refptr(new base::TestMockTimeTaskRunner()); | 
| +  base::ThreadTaskRunnerHandle handle(runner); | 
| + | 
| +  bool signaled = false; | 
| +  gl_->SetIdleCallback( | 
| +      base::Bind([](bool* signaled) { *signaled = true; }, &signaled)); | 
| +  auto busy = gl_->ClientBecameBusy(); | 
| + | 
| +  // This will trigger the idle callback to start counting down. | 
| +  gl_->ClientBecameNotBusy(std::move(busy)); | 
| + | 
| +  // Immediately take another busy lock to stop the countdown. | 
| +  busy = gl_->ClientBecameBusy(); | 
| + | 
| +  // Advance time and ensure that our callback was cancelled (does not run). | 
| +  task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 
| +  EXPECT_FALSE(signaled); | 
| + | 
| +  // Release our busy lock, and let the idle callback run. | 
| +  gl_->ClientBecameNotBusy(std::move(busy)); | 
| + | 
| +  task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 
| +  EXPECT_TRUE(signaled); | 
| +} | 
| + | 
| #include "base/macros.h" | 
| #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 
|  | 
|  |