| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/file_util.h" | |
| 6 #include "base/message_loop.h" | |
| 7 #include "base/path_service.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "googleurl/src/gurl.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "webkit/tools/test_shell/test_shell_test.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class BookmarkletTest : public TestShellTest { | |
| 16 public: | |
| 17 virtual void SetUp() { | |
| 18 TestShellTest::SetUp(); | |
| 19 | |
| 20 test_shell_->LoadURL(GURL("data:text/html,start page")); | |
| 21 test_shell_->WaitTestFinished(); | |
| 22 } | |
| 23 }; | |
| 24 | |
| 25 TEST_F(BookmarkletTest, Redirect) { | |
| 26 test_shell_->LoadURL( | |
| 27 GURL("javascript:location.href='data:text/plain,SUCCESS'")); | |
| 28 test_shell_->WaitTestFinished(); | |
| 29 string16 text = test_shell_->GetDocumentText(); | |
| 30 EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); | |
| 31 } | |
| 32 | |
| 33 TEST_F(BookmarkletTest, RedirectVoided) { | |
| 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 | |
| 36 // the evaluation of the script should suppress loading the script result. | |
| 37 // Here, because of the void() wrapping there is no script result. | |
| 38 test_shell_->LoadURL( | |
| 39 GURL("javascript:void(location.href='data:text/plain,SUCCESS')")); | |
| 40 test_shell_->WaitTestFinished(); | |
| 41 string16 text = test_shell_->GetDocumentText(); | |
| 42 EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); | |
| 43 } | |
| 44 | |
| 45 TEST_F(BookmarkletTest, NonEmptyResult) { | |
| 46 string16 text; | |
| 47 | |
| 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 | |
| 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 | |
| 52 // really an edge case. Our behavior with V8 is consistent with FF and IE. | |
| 53 #if 0 | |
| 54 test_shell_->LoadURL(L"javascript:false"); | |
| 55 MessageLoop::current()->RunAllPending(); | |
| 56 text = test_shell_->GetDocumentText(); | |
| 57 EXPECT_EQ("false", UTF16ToASCII(text)); | |
| 58 #endif | |
| 59 | |
| 60 test_shell_->LoadURL(GURL("javascript:'hello world'")); | |
| 61 MessageLoop::current()->RunAllPending(); | |
| 62 text = test_shell_->GetDocumentText(); | |
| 63 EXPECT_EQ("hello world", UTF16ToASCII(text)); | |
| 64 } | |
| 65 | |
| 66 TEST_F(BookmarkletTest, DocumentWrite) { | |
| 67 test_shell_->LoadURL(GURL( | |
| 68 "javascript:document.open();" | |
| 69 "document.write('hello world');" | |
| 70 "document.close()")); | |
| 71 MessageLoop::current()->RunAllPending(); | |
| 72 string16 text = test_shell_->GetDocumentText(); | |
| 73 EXPECT_EQ("hello world", UTF16ToASCII(text)); | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| OLD | NEW |