This source file includes following definitions.
- unlock_called_
- LockOrientation
- UnlockOrientation
- orientations
- unlock_called
- SetUp
- TEST_F
- TEST_F
- TEST_F
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
#include "content/browser/screen_orientation/screen_orientation_provider.h"
#include "content/common/screen_orientation_messages.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
class MockScreenOrientationProvider : public ScreenOrientationProvider {
public:
MockScreenOrientationProvider() : orientations_(0), unlock_called_(false) {}
virtual void LockOrientation(blink::WebScreenOrientations orientations)
OVERRIDE {
orientations_ = orientations;
}
virtual void UnlockOrientation() OVERRIDE {
unlock_called_ = true;
}
blink::WebScreenOrientations orientations() const {
return orientations_;
}
bool unlock_called() const {
return unlock_called_;
}
virtual ~MockScreenOrientationProvider() {}
private:
blink::WebScreenOrientations orientations_;
bool unlock_called_;
DISALLOW_COPY_AND_ASSIGN(MockScreenOrientationProvider);
};
class ScreenOrientationDispatcherHostTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
provider_ = new MockScreenOrientationProvider();
dispatcher_ = new ScreenOrientationDispatcherHost();
dispatcher_->SetProviderForTests(provider_);
}
MockScreenOrientationProvider* provider_;
scoped_refptr<ScreenOrientationDispatcherHost> dispatcher_;
};
TEST_F(ScreenOrientationDispatcherHostTest, NullProvider) {
dispatcher_->SetProviderForTests(NULL);
bool message_was_ok = false;
bool message_was_handled = dispatcher_->OnMessageReceived(
ScreenOrientationHostMsg_Lock(blink::WebScreenOrientationPortraitPrimary),
&message_was_ok);
EXPECT_TRUE(message_was_ok);
EXPECT_TRUE(message_was_handled);
}
TEST_F(ScreenOrientationDispatcherHostTest, ProviderLock) {
blink::WebScreenOrientations orientationsToTest[] = {
blink::WebScreenOrientationPortraitPrimary,
blink::WebScreenOrientationPortraitSecondary,
blink::WebScreenOrientationLandscapePrimary,
blink::WebScreenOrientationLandscapeSecondary,
blink::WebScreenOrientationLandscapePrimary |
blink::WebScreenOrientationPortraitPrimary,
blink::WebScreenOrientationLandscapePrimary |
blink::WebScreenOrientationPortraitSecondary,
blink::WebScreenOrientationPortraitPrimary |
blink::WebScreenOrientationPortraitSecondary |
blink::WebScreenOrientationLandscapePrimary |
blink::WebScreenOrientationLandscapeSecondary,
0,
100,
42
};
int orientationsToTestCount = 10;
for (int i = 0; i < orientationsToTestCount; ++i) {
bool message_was_ok = false;
bool message_was_handled = false;
blink::WebScreenOrientations orientations = orientationsToTest[i];
message_was_handled = dispatcher_->OnMessageReceived(
ScreenOrientationHostMsg_Lock(orientations), &message_was_ok);
EXPECT_TRUE(message_was_ok);
EXPECT_TRUE(message_was_handled);
EXPECT_EQ(orientations, provider_->orientations());
}
}
TEST_F(ScreenOrientationDispatcherHostTest, ProviderUnlock) {
bool message_was_ok = false;
bool message_was_handled = dispatcher_->OnMessageReceived(
ScreenOrientationHostMsg_Unlock(), &message_was_ok);
EXPECT_TRUE(message_was_ok);
EXPECT_TRUE(message_was_handled);
EXPECT_TRUE(provider_->unlock_called());
}
}