| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" | 
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" | 
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" | 
| 8 #include "components/translate/core/common/translate_errors.h" | 8 #include "components/translate/core/common/translate_errors.h" | 
| 9 #include "grit/components_resources.h" | 9 #include "grit/components_resources.h" | 
| 10 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 10 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102   } | 102   } | 
| 103 | 103 | 
| 104  private: | 104  private: | 
| 105   void SetUp() override { ChromeRenderViewTest::SetUp(); } | 105   void SetUp() override { ChromeRenderViewTest::SetUp(); } | 
| 106 | 106 | 
| 107   void TearDown() override { ChromeRenderViewTest::TearDown(); } | 107   void TearDown() override { ChromeRenderViewTest::TearDown(); } | 
| 108 | 108 | 
| 109   double ExecuteScriptAndGetNumberResult(const std::string& script) { | 109   double ExecuteScriptAndGetNumberResult(const std::string& script) { | 
| 110     WebScriptSource source = WebScriptSource(base::ASCIIToUTF16(script)); | 110     WebScriptSource source = WebScriptSource(base::ASCIIToUTF16(script)); | 
| 111     v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 111     v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 
| 112     v8::Handle<v8::Value> result = | 112     v8::Local<v8::Value> result = | 
| 113         GetMainFrame()->executeScriptAndReturnValue(source); | 113         GetMainFrame()->executeScriptAndReturnValue(source); | 
| 114     if (result.IsEmpty() || !result->IsNumber()) { | 114     if (result.IsEmpty() || !result->IsNumber()) { | 
| 115       NOTREACHED(); | 115       NOTREACHED(); | 
| 116       // TODO(toyoshim): Return NaN here and the real implementation in | 116       // TODO(toyoshim): Return NaN here and the real implementation in | 
| 117       // TranslateHelper::ExecuteScriptAndGetDoubleResult(). | 117       // TranslateHelper::ExecuteScriptAndGetDoubleResult(). | 
| 118       return 0.0; | 118       return 0.0; | 
| 119     } | 119     } | 
| 120     return result->NumberValue(); | 120     return result->NumberValue(); | 
| 121   } | 121   } | 
| 122 | 122 | 
| 123   bool ExecuteScriptAndGetBoolResult(const std::string& script) { | 123   bool ExecuteScriptAndGetBoolResult(const std::string& script) { | 
| 124     WebScriptSource source = WebScriptSource(base::ASCIIToUTF16(script)); | 124     WebScriptSource source = WebScriptSource(base::ASCIIToUTF16(script)); | 
| 125     v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 125     v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 
| 126     v8::Handle<v8::Value> result = | 126     v8::Local<v8::Value> result = | 
| 127         GetMainFrame()->executeScriptAndReturnValue(source); | 127         GetMainFrame()->executeScriptAndReturnValue(source); | 
| 128     if (result.IsEmpty() || !result->IsBoolean()) { | 128     if (result.IsEmpty() || !result->IsBoolean()) { | 
| 129       NOTREACHED(); | 129       NOTREACHED(); | 
| 130       return false; | 130       return false; | 
| 131     } | 131     } | 
| 132     return result->BooleanValue(); | 132     return result->BooleanValue(); | 
| 133   } | 133   } | 
| 134 | 134 | 
| 135   DISALLOW_COPY_AND_ASSIGN(TranslateScriptBrowserTest); | 135   DISALLOW_COPY_AND_ASSIGN(TranslateScriptBrowserTest); | 
| 136 }; | 136 }; | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 227   EXPECT_FALSE(GetError()); | 227   EXPECT_FALSE(GetError()); | 
| 228   EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode()); | 228   EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode()); | 
| 229 | 229 | 
| 230   ExecuteScript(kTranslate); | 230   ExecuteScript(kTranslate); | 
| 231 | 231 | 
| 232   EXPECT_TRUE(GetError()); | 232   EXPECT_TRUE(GetError()); | 
| 233   EXPECT_EQ(translate::TranslateErrors::UNSUPPORTED_LANGUAGE, GetErrorCode()); | 233   EXPECT_EQ(translate::TranslateErrors::UNSUPPORTED_LANGUAGE, GetErrorCode()); | 
| 234 } | 234 } | 
| 235 | 235 | 
| 236 // TODO(toyoshim): Add test for onLoadJavaScript. | 236 // TODO(toyoshim): Add test for onLoadJavaScript. | 
| OLD | NEW | 
|---|