| OLD | NEW |
| 1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 // History UI tests | 30 // History UI tests |
| 31 | 31 |
| 32 #include "base/file_util.h" | 32 #include "base/file_util.h" |
| 33 #include "base/gfx/point.h" | |
| 34 #include "base/gfx/rect.h" | |
| 35 #include "chrome/browser/view_ids.h" | |
| 36 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/test/automation/browser_proxy.h" | |
| 38 #include "chrome/test/automation/tab_proxy.h" | 34 #include "chrome/test/automation/tab_proxy.h" |
| 39 #include "chrome/test/automation/window_proxy.h" | |
| 40 #include "chrome/test/ui/ui_test.h" | 35 #include "chrome/test/ui/ui_test.h" |
| 41 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
| 42 #include "views/event.h" | |
| 43 | 37 |
| 44 const char kTestCompleteCookie[] = "status"; | 38 const char kTestCompleteCookie[] = "status"; |
| 45 const char kTestCompleteSuccess[] = "OK"; | 39 const char kTestCompleteSuccess[] = "OK"; |
| 46 | 40 |
| 47 class HistoryTester : public UITest { | 41 class HistoryTester : public UITest { |
| 48 protected: | 42 protected: |
| 49 HistoryTester() : UITest() { } | 43 HistoryTester() : UITest() { } |
| 50 | 44 |
| 51 virtual void SetUp() { | 45 virtual void SetUp() { |
| 52 show_window_ = true; | 46 show_window_ = true; |
| 53 UITest::SetUp(); | 47 UITest::SetUp(); |
| 54 } | 48 } |
| 55 }; | 49 }; |
| 56 | 50 |
| 57 // TODO(yuzo): Fix the following flaky (hence disabled) tests. | 51 TEST_F(HistoryTester, VerifyHistoryLength) { |
| 58 // These tests are flaky because automatic and user-initiated transitions are | |
| 59 // distinguished based on the interval between page load and redirect. | |
| 60 | |
| 61 TEST_F(HistoryTester, DISABLED_VerifyHistoryLength) { | |
| 62 // Test the history length for the following page transitions. | 52 // Test the history length for the following page transitions. |
| 63 // | 53 // |
| 64 // Test case 1: | 54 // Test case 1: |
| 65 // -open-> Page 1. | 55 // -open-> Page 1. |
| 66 // Test case 2: | 56 // Test case 2: |
| 67 // -open-> Page 2 -redirect-> Page 3. | 57 // -open-> Page 2 -redirect-> Page 3. |
| 68 // Test case 3: | 58 // Test case 3: |
| 69 // -open-> Page 4 -navigate_backward-> Page 3 -navigate_backward->Page 1 | 59 // -open-> Page 4 -navigate_backward-> Page 3 -navigate_backward->Page 1 |
| 70 // -navigate_forward-> Page 3 -navigate_forward-> Page 4 | 60 // -navigate_forward-> Page 3 -navigate_forward-> Page 4 |
| 71 // | 61 // |
| 72 // Note that Page 2 is not visited on navigating backward/forward. | 62 // Note that Page 2 is not visited on navigating backward/forward. |
| 73 | 63 |
| 74 // Test case 1 | 64 // Test case 1 |
| 75 std::wstring test_case_1 = L"history_length_test_page_1.html"; | 65 std::wstring test_case_1 = L"history_length_test_page_1.html"; |
| 76 GURL url_1 = GetTestUrl(L"History", test_case_1); | 66 GURL url_1 = GetTestUrl(L"History", test_case_1); |
| 77 NavigateToURL(url_1); | 67 NavigateToURL(url_1); |
| 78 WaitForFinish("History_Length_Test_1", "1", url_1, kTestCompleteCookie, | 68 WaitForFinish("History_Length_Test_1", "1", url_1, kTestCompleteCookie, |
| 79 kTestCompleteSuccess, action_max_timeout_ms()); | 69 kTestCompleteSuccess, action_max_timeout_ms()); |
| 80 | 70 |
| 81 // Test case 2 | 71 // Test case 2 |
| 82 std::wstring test_case_2 = L"history_length_test_page_2.html"; | 72 std::wstring test_case_2 = L"history_length_test_page_2.html"; |
| 83 GURL url_2 = GetTestUrl(L"History", test_case_2); | 73 GURL url_2 = GetTestUrl(L"History", test_case_2); |
| 84 NavigateToURL(url_2); | 74 NavigateToURL(url_2); |
| 85 WaitForFinish("History_Length_Test_2", "1", url_2, kTestCompleteCookie, | 75 WaitForFinish("History_Length_Test_2", "1", url_2, kTestCompleteCookie, |
| 86 kTestCompleteSuccess, action_max_timeout_ms()); | 76 kTestCompleteSuccess, action_max_timeout_ms()); |
| 87 | 77 |
| 88 // Test case 3 | 78 // Test case 3 |
| 89 std::wstring test_case_3 = L"history_length_test_page_4.html"; | 79 std::wstring test_case_3 = L"history_length_test_page_4.html"; |
| 90 GURL url_3 = GetTestUrl(L"History", test_case_3); | 80 GURL url_3 = GetTestUrl(L"History", test_case_3); |
| 91 NavigateToURL(url_3); | 81 NavigateToURL(url_3); |
| 92 WaitForFinish("History_Length_Test_3", "1", url_3, kTestCompleteCookie, | 82 WaitForFinish("History_Length_Test_3", "1", url_3, kTestCompleteCookie, |
| 93 kTestCompleteSuccess, action_max_timeout_ms()); | 83 kTestCompleteSuccess, action_max_timeout_ms()); |
| 94 } | 84 } |
| 95 | |
| 96 #if defined(OS_WIN) | |
| 97 // This test requires simulated mouse click, which is possible only for Windows. | |
| 98 TEST_F(HistoryTester, DISABLED_ConsiderRedirectAfterGestureAsUserInitiated) { | |
| 99 // Test the history length for the following page transition. | |
| 100 // | |
| 101 // -open-> Page 11 -slow_redirect-> Page 12. | |
| 102 // | |
| 103 // If redirect occurs after a user gesture, e.g., mouse click, the | |
| 104 // redirect is more likely to be user-initiated rather than automatic. | |
| 105 // Therefore, Page 11 should be in the history in addition to Page 12. | |
| 106 | |
| 107 std::wstring test_case = L"history_length_test_page_11.html"; | |
| 108 GURL url = GetTestUrl(L"History", test_case); | |
| 109 NavigateToURL(url); | |
| 110 WaitForFinish("History_Length_Test_11", "1", url, kTestCompleteCookie, | |
| 111 kTestCompleteSuccess, action_max_timeout_ms()); | |
| 112 | |
| 113 // Simulate click. This only works for Windows. | |
| 114 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); | |
| 115 scoped_refptr<WindowProxy> window = browser->GetWindow(); | |
| 116 gfx::Rect tab_view_bounds; | |
| 117 ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds, | |
| 118 true)); | |
| 119 POINT point(tab_view_bounds.CenterPoint().ToPOINT()); | |
| 120 ASSERT_TRUE( | |
| 121 window->SimulateOSClick(point, views::Event::EF_LEFT_BUTTON_DOWN)); | |
| 122 | |
| 123 NavigateToURL(GURL("javascript:redirectToPage12()")); | |
| 124 WaitForFinish("History_Length_Test_12", "1", url, kTestCompleteCookie, | |
| 125 kTestCompleteSuccess, action_max_timeout_ms()); | |
| 126 } | |
| 127 #endif // defined(OS_WIN) | |
| 128 | |
| 129 TEST_F(HistoryTester, DISABLED_ConsiderSlowRedirectAsUserInitiated) { | |
| 130 // Test the history length for the following page transition. | |
| 131 // | |
| 132 // -open-> Page 21 -redirect-> Page 22. | |
| 133 // | |
| 134 // If redirect occurs more than 5 seconds later after the page is loaded, | |
| 135 // the redirect is likely to be user-initiated. | |
| 136 // Therefore, Page 21 should be in the history in addition to Page 22. | |
| 137 | |
| 138 std::wstring test_case = L"history_length_test_page_21.html"; | |
| 139 GURL url = GetTestUrl(L"History", test_case); | |
| 140 NavigateToURL(url); | |
| 141 WaitForFinish("History_Length_Test_21", "1", url, kTestCompleteCookie, | |
| 142 kTestCompleteSuccess, action_max_timeout_ms()); | |
| 143 } | |
| OLD | NEW |