2
* Copyright 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* version 3 along with this program. If not, see
15
* <http://www.gnu.org/licenses/>
17
* Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
21
#include <gtest/gtest.h>
23
#include "SwitcherController.h"
24
#include "test_utils.h"
27
using namespace unity::switcher;
32
unsigned int DEFAULT_LAZY_CONSTRUCT_TIMEOUT = 20;
34
class MockSwitcherController : public Controller
37
MockSwitcherController()
39
, window_constructed_(false)
40
, view_constructed_(false)
44
MockSwitcherController(unsigned int load_timeout)
45
: Controller(load_timeout)
46
, window_constructed_(false)
47
, view_constructed_(false)
51
virtual void ConstructWindow()
53
window_constructed_ = true;
56
virtual void ConstructView()
58
view_constructed_ = true;
61
virtual void ShowView()
66
unsigned int GetConstructTimeout() const
68
return construct_timeout_;
71
bool window_constructed_;
72
bool view_constructed_;
76
TEST(TestSwitcherController, Construction)
78
Controller controller;
79
EXPECT_FALSE(controller.Visible());
82
TEST(TestSwitcherController, LazyConstructionTimeoutLength)
84
MockSwitcherController controller;
85
EXPECT_EQ(controller.GetConstructTimeout(), DEFAULT_LAZY_CONSTRUCT_TIMEOUT);
88
TEST(TestSwitcherController, LazyWindowConstruction)
90
// Setting the timeout to a lower value to speed-up the test
91
MockSwitcherController controller(2);
93
EXPECT_EQ(controller.GetConstructTimeout(), 2);
95
g_timeout_add_seconds(controller.GetConstructTimeout()/2, [] (gpointer data) -> gboolean {
96
auto controller = static_cast<MockSwitcherController*>(data);
97
EXPECT_FALSE(controller->window_constructed_);
102
Utils::WaitUntil(controller.window_constructed_, controller.GetConstructTimeout() + 1);
103
EXPECT_TRUE(controller.window_constructed_);