This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
#include "ash/wm/screen_dimmer.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
namespace ash {
namespace test {
class ScreenDimmerTest : public AshTestBase {
public:
ScreenDimmerTest() : dimmer_(NULL) {}
virtual ~ScreenDimmerTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
dimmer_ = Shell::GetPrimaryRootWindowController()->screen_dimmer();
test_api_.reset(new ScreenDimmer::TestApi(dimmer_));
}
protected:
ScreenDimmer* dimmer_;
scoped_ptr<ScreenDimmer::TestApi> test_api_;
private:
DISALLOW_COPY_AND_ASSIGN(ScreenDimmerTest);
};
TEST_F(ScreenDimmerTest, DimAndUndim) {
EXPECT_TRUE(test_api_->layer() == NULL);
dimmer_->SetDimming(false);
EXPECT_TRUE(test_api_->layer() == NULL);
dimmer_->SetDimming(true);
ASSERT_TRUE(test_api_->layer() != NULL);
ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer();
ASSERT_TRUE(!root_layer->children().empty());
EXPECT_EQ(test_api_->layer(), root_layer->children().back());
EXPECT_TRUE(test_api_->layer()->visible());
EXPECT_GT(test_api_->layer()->GetTargetOpacity(), 0.0f);
dimmer_->SetDimming(false);
ASSERT_TRUE(test_api_->layer() != NULL);
EXPECT_TRUE(test_api_->layer()->visible());
EXPECT_FLOAT_EQ(0.0f, test_api_->layer()->GetTargetOpacity());
}
TEST_F(ScreenDimmerTest, ResizeLayer) {
dimmer_->SetDimming(true);
ui::Layer* dimming_layer = test_api_->layer();
ASSERT_TRUE(dimming_layer != NULL);
ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer();
EXPECT_EQ(gfx::Rect(root_layer->bounds().size()).ToString(),
dimming_layer->bounds().ToString());
gfx::Rect kNewBounds(400, 300);
Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(kNewBounds);
EXPECT_EQ(kNewBounds.ToString(), dimming_layer->bounds().ToString());
}
}
}