| 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 10 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // same way. | 64 // same way. |
| 65 TEST_F(ExtensionAPIClientTest, CallbackDispatching) { | 65 TEST_F(ExtensionAPIClientTest, CallbackDispatching) { |
| 66 ExecuteJavaScript( | 66 ExecuteJavaScript( |
| 67 "function assert(truth, message) {" | 67 "function assert(truth, message) {" |
| 68 " if (!truth) {" | 68 " if (!truth) {" |
| 69 " throw new Error(message);" | 69 " throw new Error(message);" |
| 70 " }" | 70 " }" |
| 71 "}" | 71 "}" |
| 72 "function callback(result) {" | 72 "function callback(result) {" |
| 73 " assert(typeof result == 'object', 'result not object');" | 73 " assert(typeof result == 'object', 'result not object');" |
| 74 " assert(JSON.stringify(result) == '{\"foo\":\"bar\"}', " | 74 " assert(JSON.stringify(result) == '{\"id\":1,\"index\":1,\"windowId\":1," |
| 75 "\"selected\":true," |
| 76 "\"url\":\"http://www.google.com/\"}'," |
| 75 " 'incorrect result');" | 77 " 'incorrect result');" |
| 76 " console.log('pass')" | 78 " console.log('pass')" |
| 77 "}" | 79 "}" |
| 78 "chrome.tabs.create({}, callback);" | 80 "chrome.tabs.create({}, callback);" |
| 79 ); | 81 ); |
| 80 | 82 |
| 81 EXPECT_EQ("", GetConsoleMessage()); | 83 EXPECT_EQ("", GetConsoleMessage()); |
| 82 | 84 |
| 83 // Ok, we should have gotten a message to create a tab, grab the callback ID. | 85 // Ok, we should have gotten a message to create a tab, grab the callback ID. |
| 84 const IPC::Message* request_msg = | 86 const IPC::Message* request_msg = |
| 85 render_thread_.sink().GetUniqueMessageMatching( | 87 render_thread_.sink().GetUniqueMessageMatching( |
| 86 ViewHostMsg_ExtensionRequest::ID); | 88 ViewHostMsg_ExtensionRequest::ID); |
| 87 ASSERT_TRUE(request_msg); | 89 ASSERT_TRUE(request_msg); |
| 88 ViewHostMsg_ExtensionRequest::Param params; | 90 ViewHostMsg_ExtensionRequest::Param params; |
| 89 ViewHostMsg_ExtensionRequest::Read(request_msg, ¶ms); | 91 ViewHostMsg_ExtensionRequest::Read(request_msg, ¶ms); |
| 90 int callback_id = params.c; | 92 int callback_id = params.c; |
| 91 ASSERT_GE(callback_id, 0); | 93 ASSERT_GE(callback_id, 0); |
| 92 | 94 |
| 93 // Now send the callback a response | 95 // Now send the callback a response |
| 94 ExtensionProcessBindings::HandleResponse( | 96 ExtensionProcessBindings::HandleResponse( |
| 95 callback_id, true, "{\"foo\":\"bar\"}", ""); | 97 callback_id, true, "{\"id\":1,\"index\":1,\"windowId\":1,\"selected\":true," |
| 98 "\"url\":\"http://www.google.com/\"}", ""); |
| 96 | 99 |
| 97 // And verify that it worked | 100 // And verify that it worked |
| 98 ASSERT_EQ("pass", GetConsoleMessage()); | 101 ASSERT_EQ("pass", GetConsoleMessage()); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // The remainder of these tests exercise the client side of the various | 104 // The remainder of these tests exercise the client side of the various |
| 102 // extension functions. We test both error and success conditions, but do not | 105 // extension functions. We test both error and success conditions, but do not |
| 103 // test errors exhaustively as json schema code is well tested by itself. | 106 // test errors exhaustively as json schema code is well tested by itself. |
| 104 | 107 |
| 105 // Window API tests | 108 // Window API tests |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 "toolstrip.collapse", | 567 "toolstrip.collapse", |
| 565 "\"http://foo/\""); | 568 "\"http://foo/\""); |
| 566 | 569 |
| 567 ExpectJsFail("chrome.toolstrip.collapse(100)", | 570 ExpectJsFail("chrome.toolstrip.collapse(100)", |
| 568 "Uncaught Error: Invalid value for argument 0. " | 571 "Uncaught Error: Invalid value for argument 0. " |
| 569 "Expected 'string' but got 'integer'."); | 572 "Expected 'string' but got 'integer'."); |
| 570 ExpectJsFail("chrome.toolstrip.collapse('http://foo/', 32)", | 573 ExpectJsFail("chrome.toolstrip.collapse('http://foo/', 32)", |
| 571 "Uncaught Error: Invalid value for argument 1. " | 574 "Uncaught Error: Invalid value for argument 1. " |
| 572 "Expected 'function' but got 'integer'."); | 575 "Expected 'function' but got 'integer'."); |
| 573 } | 576 } |
| OLD | NEW |