| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/tests/test_view.h" | 5 #include "ppapi/tests/test_view.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "ppapi/c/pp_time.h" | 9 #include "ppapi/c/pp_time.h" |
| 10 #include "ppapi/c/private/ppb_testing_private.h" | 10 #include "ppapi/c/private/ppb_testing_private.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ASSERT_TRUE(last_view_.GetRect() == desired_rect); | 135 ASSERT_TRUE(last_view_.GetRect() == desired_rect); |
| 136 | 136 |
| 137 PASS(); | 137 PASS(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 std::string TestView::TestClipChange() { | 140 std::string TestView::TestClipChange() { |
| 141 pp::Rect original_rect = last_view_.GetRect(); | 141 pp::Rect original_rect = last_view_.GetRect(); |
| 142 | 142 |
| 143 // Original clip should be the full frame. | 143 // Original clip should be the full frame. |
| 144 pp::Rect original_clip = last_view_.GetClipRect(); | 144 pp::Rect original_clip = last_view_.GetClipRect(); |
| 145 ASSERT_TRUE(original_clip.x() == 0); | 145 ASSERT_TRUE(original_clip.x() == 1); |
| 146 ASSERT_TRUE(original_clip.y() == 0); | 146 ASSERT_TRUE(original_clip.y() == 1); |
| 147 ASSERT_TRUE(original_clip.width() == original_rect.width()); | 147 ASSERT_TRUE(original_clip.width() == original_rect.width()); |
| 148 ASSERT_TRUE(original_clip.height() == original_rect.height()); | 148 ASSERT_TRUE(original_clip.height() == original_rect.height()); |
| 149 | 149 |
| 150 int clip_amount = original_rect.height() / 2; | 150 int clip_amount = original_rect.height() / 2; |
| 151 | 151 |
| 152 // It might be nice to set the position to be absolute and set the location, | 152 // It might be nice to set the position to be absolute and set the location, |
| 153 // but this will cause WebKit to actually tear down the plugin and recreate | 153 // but this will cause WebKit to actually tear down the plugin and recreate |
| 154 // it. So instead we add a big div to cause the document to be scrollable, | 154 // it. So instead we add a big div to cause the document to be scrollable, |
| 155 // and scroll it down. | 155 // and scroll it down. |
| 156 std::ostringstream script_stream; | 156 std::ostringstream script_stream; |
| 157 script_stream | 157 script_stream |
| 158 << "var big = document.createElement('div');" | 158 << "var big = document.createElement('div');" |
| 159 << "big.setAttribute('style', 'position:absolute; left:100px; " | 159 << "big.setAttribute('style', 'position:absolute; left:100px; " |
| 160 "top:0px; width:1px; height:5000px;');" | 160 "top:0px; width:1px; height:5000px;');" |
| 161 << "document.body.appendChild(big);" | 161 << "document.body.appendChild(big);" |
| 162 << "window.scrollBy(0, " << original_rect.y() + clip_amount << ");"; | 162 << "window.scrollBy(0, " << original_rect.y() + clip_amount << ");"; |
| 163 | 163 |
| 164 instance_->EvalScript(script_stream.str()); | 164 instance_->EvalScript(script_stream.str()); |
| 165 | 165 |
| 166 pp::Rect desired_clip = original_clip; | 166 pp::Rect desired_clip = original_clip; |
| 167 desired_clip.set_y(clip_amount); | 167 desired_clip.set_y(clip_amount + original_clip.y()); |
| 168 desired_clip.set_height(desired_clip.height() - desired_clip.y()); | 168 desired_clip.set_height( |
| 169 desired_clip.height() - desired_clip.y() + original_clip.y()); |
| 169 | 170 |
| 170 while (WaitUntilViewChanged() && last_view_.GetClipRect() != desired_clip) { | 171 while (WaitUntilViewChanged() && last_view_.GetClipRect() != desired_clip) { |
| 171 } | 172 } |
| 172 ASSERT_TRUE(last_view_.GetClipRect() == desired_clip); | 173 ASSERT_TRUE(last_view_.GetClipRect() == desired_clip); |
| 173 PASS(); | 174 PASS(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 std::string TestView::TestScrollOffsetChange() { | 177 std::string TestView::TestScrollOffsetChange() { |
| 177 instance_->EvalScript("document.body.style.width = '5000px';" | 178 instance_->EvalScript("document.body.style.width = '5000px';" |
| 178 "document.body.style.height = '5000px';"); | 179 "document.body.style.height = '5000px';"); |
| 179 instance_->EvalScript("window.scrollTo(5, 1);"); | 180 instance_->EvalScript("window.scrollTo(5, 1);"); |
| 180 | 181 |
| 181 while (WaitUntilViewChanged() && | 182 while (WaitUntilViewChanged() && |
| 182 last_view_.GetScrollOffset() != pp::Point(5, 1)) { | 183 last_view_.GetScrollOffset() != pp::Point(5, 1)) { |
| 183 } | 184 } |
| 184 ASSERT_EQ(pp::Point(5, 1), last_view_.GetScrollOffset()); | 185 ASSERT_EQ(pp::Point(5, 1), last_view_.GetScrollOffset()); |
| 185 | 186 |
| 186 instance_->EvalScript("window.scrollTo(0, 0);"); | 187 instance_->EvalScript("window.scrollTo(0, 0);"); |
| 187 | 188 |
| 188 while (WaitUntilViewChanged() && | 189 while (WaitUntilViewChanged() && |
| 189 last_view_.GetScrollOffset() != pp::Point(0, 0)) { | 190 last_view_.GetScrollOffset() != pp::Point(0, 0)) { |
| 190 } | 191 } |
| 191 ASSERT_EQ(pp::Point(0, 0), last_view_.GetScrollOffset()); | 192 ASSERT_EQ(pp::Point(0, 0), last_view_.GetScrollOffset()); |
| 192 | 193 |
| 193 PASS(); | 194 PASS(); |
| 194 } | 195 } |
| OLD | NEW |