| 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 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/tools/test_shell/test_shell_test.h" | 11 #include "webkit/tools/test_shell/test_shell_test.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class BookmarkletTest : public TestShellTest { | 15 class BookmarkletTest : public TestShellTest { |
| 16 public: | 16 public: |
| 17 virtual void SetUp() { | 17 virtual void SetUp() { |
| 18 TestShellTest::SetUp(); | 18 TestShellTest::SetUp(); |
| 19 | 19 |
| 20 test_shell_->LoadURL(GURL("data:text/html,start page")); | 20 test_shell_->LoadURL(GURL("data:text/html,start page")); |
| 21 test_shell_->WaitTestFinished(); | 21 test_shell_->WaitTestFinished(); |
| 22 } | 22 } |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 TEST_F(BookmarkletTest, Redirect) { | 25 TEST_F(BookmarkletTest, Redirect) { |
| 26 test_shell_->LoadURL( | 26 test_shell_->LoadURL( |
| 27 GURL("javascript:location.href='data:text/plain,SUCCESS'")); | 27 GURL("javascript:location.href='data:text/plain,SUCCESS'")); |
| 28 test_shell_->WaitTestFinished(); | 28 test_shell_->WaitTestFinished(); |
| 29 std::wstring text = test_shell_->GetDocumentText(); | 29 string16 text = test_shell_->GetDocumentText(); |
| 30 EXPECT_EQ(L"SUCCESS", text); | 30 EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 TEST_F(BookmarkletTest, RedirectVoided) { | 33 TEST_F(BookmarkletTest, RedirectVoided) { |
| 34 // This test should be redundant with the Redirect test above. The point | 34 // This test should be redundant with the Redirect test above. The point |
| 35 // here is to emphasize that in either case the assignment to location during | 35 // here is to emphasize that in either case the assignment to location during |
| 36 // the evaluation of the script should suppress loading the script result. | 36 // the evaluation of the script should suppress loading the script result. |
| 37 // Here, because of the void() wrapping there is no script result. | 37 // Here, because of the void() wrapping there is no script result. |
| 38 test_shell_->LoadURL( | 38 test_shell_->LoadURL( |
| 39 GURL("javascript:void(location.href='data:text/plain,SUCCESS')")); | 39 GURL("javascript:void(location.href='data:text/plain,SUCCESS')")); |
| 40 test_shell_->WaitTestFinished(); | 40 test_shell_->WaitTestFinished(); |
| 41 std::wstring text = test_shell_->GetDocumentText(); | 41 string16 text = test_shell_->GetDocumentText(); |
| 42 EXPECT_EQ(L"SUCCESS", text); | 42 EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 TEST_F(BookmarkletTest, NonEmptyResult) { | 45 TEST_F(BookmarkletTest, NonEmptyResult) { |
| 46 std::wstring text; | 46 string16 text; |
| 47 | 47 |
| 48 // TODO(darin): This test fails in a JSC build. WebCore+JSC does not really | 48 // TODO(darin): This test fails in a JSC build. WebCore+JSC does not really |
| 49 // need to support this usage until WebCore supports javascript: URLs that | 49 // need to support this usage until WebCore supports javascript: URLs that |
| 50 // generate content (https://bugs.webkit.org/show_bug.cgi?id=14959). It is | 50 // generate content (https://bugs.webkit.org/show_bug.cgi?id=14959). It is |
| 51 // important to note that Safari does not support bookmarklets, and this is | 51 // important to note that Safari does not support bookmarklets, and this is |
| 52 // really an edge case. Our behavior with V8 is consistent with FF and IE. | 52 // really an edge case. Our behavior with V8 is consistent with FF and IE. |
| 53 #if 0 | 53 #if 0 |
| 54 test_shell_->LoadURL(L"javascript:false"); | 54 test_shell_->LoadURL(L"javascript:false"); |
| 55 MessageLoop::current()->RunAllPending(); | 55 MessageLoop::current()->RunAllPending(); |
| 56 text = test_shell_->GetDocumentText(); | 56 text = test_shell_->GetDocumentText(); |
| 57 EXPECT_EQ(L"false", text); | 57 EXPECT_EQ("false", UTF16ToASCII(text)); |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 test_shell_->LoadURL(GURL("javascript:'hello world'")); | 60 test_shell_->LoadURL(GURL("javascript:'hello world'")); |
| 61 MessageLoop::current()->RunAllPending(); | 61 MessageLoop::current()->RunAllPending(); |
| 62 text = test_shell_->GetDocumentText(); | 62 text = test_shell_->GetDocumentText(); |
| 63 EXPECT_EQ(L"hello world", text); | 63 EXPECT_EQ("hello world", UTF16ToASCII(text)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(BookmarkletTest, DocumentWrite) { | 66 TEST_F(BookmarkletTest, DocumentWrite) { |
| 67 test_shell_->LoadURL(GURL( | 67 test_shell_->LoadURL(GURL( |
| 68 "javascript:document.open();" | 68 "javascript:document.open();" |
| 69 "document.write('hello world');" | 69 "document.write('hello world');" |
| 70 "document.close()")); | 70 "document.close()")); |
| 71 MessageLoop::current()->RunAllPending(); | 71 MessageLoop::current()->RunAllPending(); |
| 72 std::wstring text = test_shell_->GetDocumentText(); | 72 string16 text = test_shell_->GetDocumentText(); |
| 73 EXPECT_EQ(L"hello world", text); | 73 EXPECT_EQ("hello world", UTF16ToASCII(text)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| OLD | NEW |