forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New browser tests for Device Motion/Orientation.
The new browser tests follow the shared memory implementation and supersede the old test using IPC messages. The OrientationTest is currently disabled and should be enabled once the Blink side switches to the shared memory implementation for Device Orientation as well. BUG=261165 NOTRY=true Review URL: https://codereview.chromium.org/24565002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225702 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
timvolodine@chromium.org
committed
Sep 27, 2013
1 parent
29bfc76
commit c045a73
Showing
6 changed files
with
235 additions
and
80 deletions.
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
content/browser/device_orientation/device_inertial_sensor_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/command_line.h" | ||
#include "base/synchronization/waitable_event.h" | ||
#include "content/browser/device_orientation/data_fetcher_shared_memory.h" | ||
#include "content/browser/device_orientation/device_inertial_sensor_service.h" | ||
#include "content/common/device_motion_hardware_buffer.h" | ||
#include "content/common/device_orientation/device_orientation_hardware_buffer.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/common/content_switches.h" | ||
#include "content/shell/browser/shell.h" | ||
#include "content/test/content_browser_test.h" | ||
#include "content/test/content_browser_test_utils.h" | ||
|
||
namespace content { | ||
|
||
namespace { | ||
|
||
class FakeDataFetcher : public DataFetcherSharedMemory { | ||
public: | ||
FakeDataFetcher() | ||
: started_orientation_(false), | ||
stopped_orientation_(false), | ||
started_motion_(false), | ||
stopped_motion_(false) { | ||
} | ||
virtual ~FakeDataFetcher() { } | ||
|
||
virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { | ||
EXPECT_TRUE(buffer); | ||
|
||
switch (consumer_type) { | ||
case CONSUMER_TYPE_MOTION: | ||
UpdateMotion(static_cast<DeviceMotionHardwareBuffer*>(buffer)); | ||
started_motion_ = true; | ||
break; | ||
case CONSUMER_TYPE_ORIENTATION: | ||
UpdateOrientation( | ||
static_cast<DeviceOrientationHardwareBuffer*>(buffer)); | ||
started_orientation_ = true; | ||
break; | ||
default: | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
virtual bool Stop(ConsumerType consumer_type) OVERRIDE { | ||
switch (consumer_type) { | ||
case CONSUMER_TYPE_MOTION: | ||
stopped_motion_ = true; | ||
break; | ||
case CONSUMER_TYPE_ORIENTATION: | ||
stopped_orientation_ = true; | ||
break; | ||
default: | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void UpdateMotion(DeviceMotionHardwareBuffer* buffer) { | ||
buffer->seqlock.WriteBegin(); | ||
buffer->data.accelerationX = 1; | ||
buffer->data.hasAccelerationX = true; | ||
buffer->data.accelerationY = 2; | ||
buffer->data.hasAccelerationY = true; | ||
buffer->data.accelerationZ = 3; | ||
buffer->data.hasAccelerationZ = true; | ||
|
||
buffer->data.accelerationIncludingGravityX = 4; | ||
buffer->data.hasAccelerationIncludingGravityX = true; | ||
buffer->data.accelerationIncludingGravityY = 5; | ||
buffer->data.hasAccelerationIncludingGravityY = true; | ||
buffer->data.accelerationIncludingGravityZ = 6; | ||
buffer->data.hasAccelerationIncludingGravityZ = true; | ||
|
||
buffer->data.rotationRateAlpha = 7; | ||
buffer->data.hasRotationRateAlpha = true; | ||
buffer->data.rotationRateBeta = 8; | ||
buffer->data.hasRotationRateBeta = true; | ||
buffer->data.rotationRateGamma = 9; | ||
buffer->data.hasRotationRateGamma = true; | ||
|
||
buffer->data.interval = 100; | ||
buffer->data.allAvailableSensorsAreActive = true; | ||
buffer->seqlock.WriteEnd(); | ||
} | ||
|
||
void UpdateOrientation(DeviceOrientationHardwareBuffer* buffer) { | ||
buffer->seqlock.WriteBegin(); | ||
buffer->data.alpha = 1; | ||
buffer->data.hasAlpha = true; | ||
buffer->data.beta = 2; | ||
buffer->data.hasBeta = true; | ||
buffer->data.gamma = 3; | ||
buffer->data.hasGamma = true; | ||
buffer->data.allAvailableSensorsAreActive = true; | ||
buffer->seqlock.WriteEnd(); | ||
} | ||
|
||
virtual bool IsPolling() const OVERRIDE { | ||
return false; | ||
} | ||
|
||
bool started_orientation_; | ||
bool stopped_orientation_; | ||
bool started_motion_; | ||
bool stopped_motion_; | ||
|
||
private: | ||
|
||
DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | ||
}; | ||
|
||
|
||
class DeviceInertialSensorBrowserTest : public ContentBrowserTest { | ||
public: | ||
DeviceInertialSensorBrowserTest() | ||
: fetcher_(NULL), | ||
io_loop_finished_event_(false, false) { | ||
} | ||
|
||
// From ContentBrowserTest. | ||
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | ||
EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceOrientation)); | ||
EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableDeviceMotion)); | ||
} | ||
|
||
virtual void SetUpOnMainThread() OVERRIDE { | ||
BrowserThread::PostTask( | ||
BrowserThread::IO, FROM_HERE, | ||
base::Bind(&DeviceInertialSensorBrowserTest::SetUpOnIOThread, this)); | ||
io_loop_finished_event_.Wait(); | ||
} | ||
|
||
void SetUpOnIOThread() { | ||
fetcher_ = new FakeDataFetcher(); | ||
DeviceInertialSensorService::GetInstance()-> | ||
SetDataFetcherForTests(fetcher_); | ||
io_loop_finished_event_.Signal(); | ||
} | ||
|
||
FakeDataFetcher* fetcher_; | ||
|
||
private: | ||
base::WaitableEvent io_loop_finished_event_; | ||
}; | ||
|
||
|
||
// TODO(timvolodine): enable this test once the blink side has switched to | ||
// the shared memory implementation (crbug.com/298066). | ||
IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | ||
DISABLED_OrientationTest) { | ||
// The test page will register an event handler for orientation events, | ||
// expects to get an event with fake values, then removes the event | ||
// handler and navigates to #pass. | ||
GURL test_url = GetTestUrl( | ||
"device_orientation", "device_orientation_test.html"); | ||
NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | ||
|
||
EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | ||
EXPECT_TRUE(fetcher_->started_orientation_); | ||
EXPECT_TRUE(fetcher_->stopped_orientation_); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { | ||
// The test page will register an event handler for motion events, | ||
// expects to get an event with fake values, then removes the event | ||
// handler and navigates to #pass. | ||
GURL test_url = GetTestUrl( | ||
"device_orientation", "device_motion_test.html"); | ||
NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | ||
|
||
EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | ||
EXPECT_TRUE(fetcher_->started_motion_); | ||
EXPECT_TRUE(fetcher_->stopped_motion_); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
content/browser/device_orientation/device_orientation_browsertest.cc
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
content/test/data/device_orientation/device_motion_test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<html> | ||
<head> | ||
<title>DeviceMotion test</title> | ||
<script type="text/javascript"> | ||
function checkMotionEvent(event) { | ||
return event.acceleration.x == 1 && | ||
event.acceleration.y == 2 && | ||
event.acceleration.z == 3 && | ||
event.accelerationIncludingGravity.x == 4 && | ||
event.accelerationIncludingGravity.y == 5 && | ||
event.accelerationIncludingGravity.z == 6 && | ||
event.rotationRate.alpha == 7 && | ||
event.rotationRate.beta == 8 && | ||
event.rotationRate.gamma == 9 && | ||
event.interval == 100; | ||
} | ||
|
||
function onMotion(event) { | ||
if (checkMotionEvent(event)) { | ||
window.removeEventListener('devicemotion', onMotion); | ||
pass(); | ||
} else { | ||
fail(); | ||
} | ||
} | ||
|
||
function pass() { | ||
document.getElementById('status').innerHTML = 'PASS'; | ||
document.location = '#pass'; | ||
} | ||
|
||
function fail() { | ||
document.location = '#fail'; | ||
} | ||
</script> | ||
</head> | ||
<body onLoad="window.addEventListener('devicemotion', onMotion)"> | ||
<div id="status">FAIL</div> | ||
</body> | ||
</html> |