1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_STATE_TEST_H_
#define CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_STATE_TEST_H_
#include <sstream>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "build/build_config.h"
class Browser;
class FullscreenController;
// Test fixture testing Fullscreen Controller through its states. --------------
class FullscreenControllerStateTest {
public:
enum State {
// The window is not in fullscreen.
STATE_NORMAL,
// User-initiated fullscreen.
STATE_BROWSER_FULLSCREEN_NO_CHROME,
// Mac User-initiated 'Lion Fullscreen' with browser chrome. OSX 10.7+ only.
STATE_BROWSER_FULLSCREEN_WITH_CHROME,
// Windows 8 Metro Snap mode, which puts the window at 20% screen-width.
// No TO_ state for Metro, as the windows implementation is only reentrant.
STATE_METRO_SNAP,
// HTML5 tab-initiated fullscreen.
STATE_TAB_FULLSCREEN,
// Both tab and browser fullscreen.
STATE_TAB_BROWSER_FULLSCREEN,
// Both tab and browser fullscreen, displayed without chrome, but exits tab
// fullscreen to STATE_BROWSER_FULLSCREEN_WITH_CHROME.
STATE_TAB_BROWSER_FULLSCREEN_CHROME,
// TO_ states are asynchronous states waiting for window state change
// before transitioning to their named state.
STATE_TO_NORMAL,
STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,
STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,
STATE_TO_TAB_FULLSCREEN,
NUM_STATES,
STATE_INVALID,
};
enum Event {
// FullscreenController::ToggleFullscreenMode()
TOGGLE_FULLSCREEN,
// FullscreenController::ToggleFullscreenWithChrome()
TOGGLE_FULLSCREEN_CHROME,
// FullscreenController::ToggleFullscreenModeForTab(, true)
TAB_FULLSCREEN_TRUE,
// FullscreenController::ToggleFullscreenModeForTab(, false)
TAB_FULLSCREEN_FALSE,
// FullscreenController::SetMetroSnapMode(true)
METRO_SNAP_TRUE,
// FullscreenController::SetMetroSnapMode(flase)
METRO_SNAP_FALSE,
// FullscreenController::ExitTabOrBrowserFullscreenToPreviousState
BUBBLE_EXIT_LINK,
// FullscreenController::OnAcceptFullscreenPermission
BUBBLE_ALLOW,
// FullscreenController::OnDenyFullscreenPermission
BUBBLE_DENY,
// FullscreenController::ChangeWindowFullscreenState()
WINDOW_CHANGE,
NUM_EVENTS,
EVENT_INVALID,
};
static const int MAX_STATE_NAME_LENGTH = 39;
static const int MAX_EVENT_NAME_LENGTH = 24;
FullscreenControllerStateTest();
virtual ~FullscreenControllerStateTest();
static const char* GetStateString(State state);
static const char* GetEventString(Event event);
// Causes Fullscreen Controller to transition to an arbitrary state.
void TransitionToState(State state);
// Makes one state change to approach |destination_state| via shortest path.
// Returns true if a state change is made.
// Repeated calls are needed to reach the destination.
bool TransitionAStepTowardState(State destination_state);
virtual void ChangeWindowFullscreenState() {}
virtual const char* GetWindowStateString();
// Causes the |event| to occur and return true on success.
virtual bool InvokeEvent(Event event);
// Checks that window state matches the expected controller state.
virtual void VerifyWindowState();
// Tests all states with all permutations of multiple events to detect
// lingering state issues that would bleed over to other states.
// I.E. for each state test all combinations of events E1, E2, E3.
//
// This produces coverage for event sequences that may happen normally but
// would not be exposed by traversing to each state via TransitionToState().
// TransitionToState() always takes the same path even when multiple paths
// exist.
void TestTransitionsForEachState();
// Log transition_table_ to a string for debugging.
std::string GetTransitionTableAsString() const;
// Log state_transitions_ to a string for debugging.
std::string GetStateTransitionsAsString() const;
protected:
// Generated information about the transitions between states.
struct StateTransitionInfo {
StateTransitionInfo()
: event(EVENT_INVALID),
state(STATE_INVALID),
distance(NUM_STATES) {}
Event event; // The |Event| that will cause the state transition.
State state; // The adjacent |State| transitioned to; not the final state.
int distance; // Steps to final state. NUM_STATES represents unknown.
};
// Returns next transition info for shortest path from source to destination.
StateTransitionInfo NextTransitionInShortestPath(State source,
State destination,
int search_limit);
std::string GetAndClearDebugLog();
// Avoids currently broken cases in the fullscreen controller.
virtual bool ShouldSkipStateAndEventPair(State state, Event event);
// Skips reentrant situations and calls ShouldSkipStateAndEventPair.
virtual bool ShouldSkipTest(State state, Event event, bool reentrant);
// Runs one test of transitioning to a state and invoking an event.
virtual void TestStateAndEvent(State state, Event event, bool reentrant);
virtual Browser* GetBrowser() = 0;
FullscreenController* GetFullscreenController();
State state_;
bool reentrant_;
// Human defined |State| that results given each [state][event] pair.
State transition_table_[NUM_STATES][NUM_EVENTS];
// Generated information about the transitions between states [from][to].
// View generated data with: out/Release/unit_tests
// --gtest_filter="FullscreenController*DebugLogStateTables"
// --gtest_also_run_disabled_tests
StateTransitionInfo state_transitions_[NUM_STATES][NUM_STATES];
// Log of operations reported on errors via GetAndClearDebugLog().
std::ostringstream debugging_log_;
DISALLOW_COPY_AND_ASSIGN(FullscreenControllerStateTest);
};
#endif // CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_STATE_TEST_H_
|