| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api_test_utils.h" | 5 #include "extensions/browser/api_test_utils.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
| 12 #include "extensions/browser/extension_function.h" | 12 #include "extensions/browser/extension_function.h" |
| 13 #include "extensions/browser/extension_function_dispatcher.h" | 13 #include "extensions/browser/extension_function_dispatcher.h" |
| 14 #include "extensions/common/extension_builder.h" | 14 #include "extensions/common/extension_builder.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using extensions::ExtensionFunctionDispatcher; | 17 using extensions::ExtensionFunctionDispatcher; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class TestFunctionDispatcherDelegate | 21 class TestFunctionDispatcherDelegate |
| 22 : public ExtensionFunctionDispatcher::Delegate { | 22 : public ExtensionFunctionDispatcher::Delegate { |
| 23 public: | 23 public: |
| 24 TestFunctionDispatcherDelegate() {} | 24 TestFunctionDispatcherDelegate() {} |
| 25 virtual ~TestFunctionDispatcherDelegate() {} | 25 ~TestFunctionDispatcherDelegate() override {} |
| 26 | 26 |
| 27 // NULL implementation. | 27 // NULL implementation. |
| 28 private: | 28 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); | 29 DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 base::Value* ParseJSON(const std::string& data) { | 32 base::Value* ParseJSON(const std::string& data) { |
| 33 return base::JSONReader::Read(data); | 33 return base::JSONReader::Read(data); |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 should_post_quit_ = should_quit; | 53 should_post_quit_ = should_quit; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool HasResponse() { return response_.get() != NULL; } | 56 bool HasResponse() { return response_.get() != NULL; } |
| 57 | 57 |
| 58 bool GetResponse() { | 58 bool GetResponse() { |
| 59 EXPECT_TRUE(HasResponse()); | 59 EXPECT_TRUE(HasResponse()); |
| 60 return *response_.get(); | 60 return *response_.get(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual void OnSendResponse(UIThreadExtensionFunction* function, | 63 void OnSendResponse(UIThreadExtensionFunction* function, |
| 64 bool success, | 64 bool success, |
| 65 bool bad_message) override { | 65 bool bad_message) override { |
| 66 ASSERT_FALSE(bad_message); | 66 ASSERT_FALSE(bad_message); |
| 67 ASSERT_FALSE(HasResponse()); | 67 ASSERT_FALSE(HasResponse()); |
| 68 response_.reset(new bool); | 68 response_.reset(new bool); |
| 69 *response_ = success; | 69 *response_ = success; |
| 70 if (should_post_quit_) { | 70 if (should_post_quit_) { |
| 71 base::MessageLoopForUI::current()->Quit(); | 71 base::MessageLoopForUI::current()->Quit(); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 response_delegate.set_should_post_quit(true); | 196 response_delegate.set_should_post_quit(true); |
| 197 content::RunMessageLoop(); | 197 content::RunMessageLoop(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 EXPECT_TRUE(response_delegate.HasResponse()); | 200 EXPECT_TRUE(response_delegate.HasResponse()); |
| 201 return response_delegate.GetResponse(); | 201 return response_delegate.GetResponse(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace api_test_utils | 204 } // namespace api_test_utils |
| 205 } // namespace extensions | 205 } // namespace extensions |
| OLD | NEW |