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