| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_browsertest.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 void BrowserPluginTest::TearDown() { | 94 void BrowserPluginTest::TearDown() { |
| 95 BrowserPluginManager::set_factory_for_testing( | 95 BrowserPluginManager::set_factory_for_testing( |
| 96 TestBrowserPluginManagerFactory::GetInstance()); | 96 TestBrowserPluginManagerFactory::GetInstance()); |
| 97 content::RenderViewTest::TearDown(); | 97 content::RenderViewTest::TearDown(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 std::string BrowserPluginTest::ExecuteScriptAndReturnString( | 100 std::string BrowserPluginTest::ExecuteScriptAndReturnString( |
| 101 const std::string& script) { | 101 const std::string& script) { |
| 102 v8::HandleScope handle_scope; |
| 102 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( | 103 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
| 103 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); | 104 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); |
| 104 if (value.IsEmpty() || !value->IsString()) | 105 if (value.IsEmpty() || !value->IsString()) |
| 105 return std::string(); | 106 return std::string(); |
| 106 | 107 |
| 107 v8::Local<v8::String> v8_str = value->ToString(); | 108 v8::Local<v8::String> v8_str = value->ToString(); |
| 108 int length = v8_str->Utf8Length() + 1; | 109 int length = v8_str->Utf8Length() + 1; |
| 109 scoped_array<char> str(new char[length]); | 110 scoped_array<char> str(new char[length]); |
| 110 v8_str->WriteUtf8(str.get(), length); | 111 v8_str->WriteUtf8(str.get(), length); |
| 111 return str.get(); | 112 return str.get(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 int BrowserPluginTest::ExecuteScriptAndReturnInt( | 115 int BrowserPluginTest::ExecuteScriptAndReturnInt( |
| 115 const std::string& script) { | 116 const std::string& script) { |
| 117 v8::HandleScope handle_scope; |
| 116 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( | 118 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
| 117 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); | 119 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); |
| 118 if (value.IsEmpty() || !value->IsInt32()) | 120 if (value.IsEmpty() || !value->IsInt32()) |
| 119 return 0; | 121 return 0; |
| 120 | 122 |
| 121 return value->Int32Value(); | 123 return value->Int32Value(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 // A return value of false means that a value was not present. The return value | 126 // A return value of false means that a value was not present. The return value |
| 125 // of the script is stored in |result| | 127 // of the script is stored in |result| |
| 126 bool BrowserPluginTest::ExecuteScriptAndReturnBool( | 128 bool BrowserPluginTest::ExecuteScriptAndReturnBool( |
| 127 const std::string& script, bool* result) { | 129 const std::string& script, bool* result) { |
| 130 v8::HandleScope handle_scope; |
| 128 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( | 131 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
| 129 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); | 132 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); |
| 130 if (value.IsEmpty() || !value->IsBoolean()) | 133 if (value.IsEmpty() || !value->IsBoolean()) |
| 131 return false; | 134 return false; |
| 132 | 135 |
| 133 *result = value->BooleanValue(); | 136 *result = value->BooleanValue(); |
| 134 return true; | 137 return true; |
| 135 } | 138 } |
| 136 | 139 |
| 137 // This test verifies that an initial resize occurs when we instantiate the | 140 // This test verifies that an initial resize occurs when we instantiate the |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 // These value are not populated (as an optimization) if autosize is | 896 // These value are not populated (as an optimization) if autosize is |
| 894 // disabled. | 897 // disabled. |
| 895 EXPECT_EQ(0, auto_size_params.min_size.width()); | 898 EXPECT_EQ(0, auto_size_params.min_size.width()); |
| 896 EXPECT_EQ(0, auto_size_params.min_size.height()); | 899 EXPECT_EQ(0, auto_size_params.min_size.height()); |
| 897 EXPECT_EQ(0, auto_size_params.max_size.width()); | 900 EXPECT_EQ(0, auto_size_params.max_size.width()); |
| 898 EXPECT_EQ(0, auto_size_params.max_size.height()); | 901 EXPECT_EQ(0, auto_size_params.max_size.height()); |
| 899 } | 902 } |
| 900 } | 903 } |
| 901 | 904 |
| 902 } // namespace content | 905 } // namespace content |
| OLD | NEW |