| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Tests for CppBoundClass, in conjunction with CppBindingExample. Binds | 5 // Tests for CppBoundClass, in conjunction with CppBindingExample. Binds |
| 6 // a CppBindingExample class into JavaScript in a custom test shell and tests | 6 // a CppBindingExample class into JavaScript in a custom test shell and tests |
| 7 // the binding from the outside by loading JS into the shell. | 7 // the binding from the outside by loading JS into the shell. |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "webkit/api/public/WebData.h" | 12 #include "webkit/api/public/WebData.h" |
| 13 #include "webkit/api/public/WebFrame.h" |
| 13 #include "webkit/api/public/WebURL.h" | 14 #include "webkit/api/public/WebURL.h" |
| 14 #include "webkit/glue/cpp_binding_example.h" | 15 #include "webkit/glue/cpp_binding_example.h" |
| 15 #include "webkit/glue/webkit_glue.h" | 16 #include "webkit/glue/webkit_glue.h" |
| 16 #include "webkit/glue/webframe.h" | |
| 17 #include "webkit/glue/webview.h" | 17 #include "webkit/glue/webview.h" |
| 18 #include "webkit/tools/test_shell/test_shell_test.h" | 18 #include "webkit/tools/test_shell/test_shell_test.h" |
| 19 | 19 |
| 20 using WebKit::WebFrame; |
| 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 class CppBindingExampleSubObject : public CppBindingExample { | 24 class CppBindingExampleSubObject : public CppBindingExample { |
| 23 public: | 25 public: |
| 24 CppBindingExampleSubObject() { | 26 CppBindingExampleSubObject() { |
| 25 sub_value_.Set("sub!"); | 27 sub_value_.Set("sub!"); |
| 26 BindProperty("sub_value", &sub_value_); | 28 BindProperty("sub_value", &sub_value_); |
| 27 } | 29 } |
| 28 private: | 30 private: |
| 29 CppVariant sub_value_; | 31 CppVariant sub_value_; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 // Wraps the given JavaScript snippet in <html><body><script> tags, then | 98 // Wraps the given JavaScript snippet in <html><body><script> tags, then |
| 97 // loads it into a webframe so it is executed. | 99 // loads it into a webframe so it is executed. |
| 98 void ExecuteJavaScript(const std::string& javascript) { | 100 void ExecuteJavaScript(const std::string& javascript) { |
| 99 std::string html = "<html><body>"; | 101 std::string html = "<html><body>"; |
| 100 html.append(TestShellTest::kJavascriptDelayExitScript); | 102 html.append(TestShellTest::kJavascriptDelayExitScript); |
| 101 html.append("<script>"); | 103 html.append("<script>"); |
| 102 html.append(javascript); | 104 html.append(javascript); |
| 103 html.append("</script></body></html>"); | 105 html.append("</script></body></html>"); |
| 104 // The base URL doesn't matter. | 106 // The base URL doesn't matter. |
| 105 webframe_->LoadHTMLString(html, GURL("about:blank")); | 107 webframe_->loadHTMLString(html, GURL("about:blank")); |
| 106 | 108 |
| 107 test_shell_->WaitTestFinished(); | 109 test_shell_->WaitTestFinished(); |
| 108 } | 110 } |
| 109 | 111 |
| 110 // Executes the specified JavaScript and checks to be sure that the resulting | 112 // Executes the specified JavaScript and checks to be sure that the resulting |
| 111 // document text is exactly "SUCCESS". | 113 // document text is exactly "SUCCESS". |
| 112 void CheckJavaScriptSuccess(const std::string& javascript) { | 114 void CheckJavaScriptSuccess(const std::string& javascript) { |
| 113 ExecuteJavaScript(javascript); | 115 ExecuteJavaScript(javascript); |
| 114 EXPECT_EQ(L"SUCCESS", webkit_glue::DumpDocumentText(webframe_)); | 116 EXPECT_EQ(L"SUCCESS", webkit_glue::DumpDocumentText(webframe_)); |
| 115 } | 117 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 260 |
| 259 // Ensures existent methods can be invoked successfully when the fallback method | 261 // Ensures existent methods can be invoked successfully when the fallback method |
| 260 // is used | 262 // is used |
| 261 TEST_F(CppBoundClassWithFallbackMethodTest, | 263 TEST_F(CppBoundClassWithFallbackMethodTest, |
| 262 InvokeExistentMethodsWithFallback) { | 264 InvokeExistentMethodsWithFallback) { |
| 263 std::string js = BuildJSCondition("example.echoValue(34)", "34"); | 265 std::string js = BuildJSCondition("example.echoValue(34)", "34"); |
| 264 CheckJavaScriptSuccess(js); | 266 CheckJavaScriptSuccess(js); |
| 265 } | 267 } |
| 266 | 268 |
| 267 } // namespace | 269 } // namespace |
| OLD | NEW |