OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/json_reader.h" |
6 #include "base/path_service.h" | 7 #include "base/path_service.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 11 #include "chrome/renderer/extensions/extension_process_bindings.h" |
11 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | 12 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
12 #include "chrome/test/render_view_test.h" | 13 #include "chrome/test/render_view_test.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 class ExtensionAPIClientTest : public RenderViewTest { | 16 class ExtensionAPIClientTest : public RenderViewTest { |
(...skipping 30 matching lines...) Expand all Loading... |
46 const std::string& arg1) { | 47 const std::string& arg1) { |
47 ExecuteJavaScript(js.c_str()); | 48 ExecuteJavaScript(js.c_str()); |
48 const IPC::Message* request_msg = | 49 const IPC::Message* request_msg = |
49 render_thread_.sink().GetUniqueMessageMatching( | 50 render_thread_.sink().GetUniqueMessageMatching( |
50 ViewHostMsg_ExtensionRequest::ID); | 51 ViewHostMsg_ExtensionRequest::ID); |
51 ASSERT_EQ("", GetConsoleMessage()) << js; | 52 ASSERT_EQ("", GetConsoleMessage()) << js; |
52 ASSERT_TRUE(request_msg) << js; | 53 ASSERT_TRUE(request_msg) << js; |
53 ViewHostMsg_ExtensionRequest::Param params; | 54 ViewHostMsg_ExtensionRequest::Param params; |
54 ViewHostMsg_ExtensionRequest::Read(request_msg, ¶ms); | 55 ViewHostMsg_ExtensionRequest::Read(request_msg, ¶ms); |
55 ASSERT_EQ(function.c_str(), params.a) << js; | 56 ASSERT_EQ(function.c_str(), params.a) << js; |
56 ASSERT_EQ(arg1.c_str(), params.b) << js; | 57 |
| 58 Value* args = NULL; |
| 59 ASSERT_TRUE(params.b.IsType(Value::TYPE_LIST)); |
| 60 ASSERT_TRUE(static_cast<const ListValue*>(¶ms.b)->Get(0, &args)); |
| 61 |
| 62 JSONReader reader; |
| 63 Value* arg1_value = reader.JsonToValue(arg1, false, false); |
| 64 ASSERT_TRUE(args->Equals(arg1_value)) << js; |
57 render_thread_.sink().ClearMessages(); | 65 render_thread_.sink().ClearMessages(); |
58 } | 66 } |
59 }; | 67 }; |
60 | 68 |
61 // Tests that callback dispatching works correctly and that JSON is properly | 69 // Tests that callback dispatching works correctly and that JSON is properly |
62 // deserialized before handing off to the extension code. We use the createTab | 70 // deserialized before handing off to the extension code. We use the createTab |
63 // API here, but we could use any of them since they all dispatch callbacks the | 71 // API here, but we could use any of them since they all dispatch callbacks the |
64 // same way. | 72 // same way. |
65 TEST_F(ExtensionAPIClientTest, CallbackDispatching) { | 73 TEST_F(ExtensionAPIClientTest, CallbackDispatching) { |
66 ExecuteJavaScript( | 74 ExecuteJavaScript( |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 624 |
617 ExpectJsFail("chrome.i18n.getMessage('name', [])", | 625 ExpectJsFail("chrome.i18n.getMessage('name', [])", |
618 "Uncaught Error: Invalid value for argument 1. Value does not " | 626 "Uncaught Error: Invalid value for argument 1. Value does not " |
619 "match any valid type choices."); | 627 "match any valid type choices."); |
620 | 628 |
621 ExpectJsFail("chrome.i18n.getMessage('name', ['p1', 'p2', 'p3', 'p4', 'p5', " | 629 ExpectJsFail("chrome.i18n.getMessage('name', ['p1', 'p2', 'p3', 'p4', 'p5', " |
622 "'p6', 'p7', 'p8', 'p9', 'p10'])", | 630 "'p6', 'p7', 'p8', 'p9', 'p10'])", |
623 "Uncaught Error: Invalid value for argument 1. Value does not " | 631 "Uncaught Error: Invalid value for argument 1. Value does not " |
624 "match any valid type choices."); | 632 "match any valid type choices."); |
625 } | 633 } |
OLD | NEW |