15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <memory.h>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <iomanip>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <iostream>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/fullscreen.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/web_contents.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/url_constants.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/mac/mac_util.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochbool SupportsMacSystemFullscreen() {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  return chrome::mac::SupportsSystemFullscreen();
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FullscreenControllerStateTest::FullscreenControllerStateTest()
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : state_(STATE_NORMAL),
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      last_notification_received_state_(STATE_NORMAL) {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Human specified state machine data.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For each state, for each event, define the resulting state.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State transition_table_data[][NUM_EVENTS] = {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    { // STATE_NORMAL:
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TOGGLE_FULLSCREEN
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event TOGGLE_FULLSCREEN_CHROME
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event TAB_FULLSCREEN_TRUE
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_NORMAL,                           // Event TAB_FULLSCREEN_FALSE
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_NORMAL,                           // Event METRO_SNAP_FALSE
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_NORMAL,                           // Event BUBBLE_EXIT_LINK
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_NORMAL,                           // Event BUBBLE_ALLOW
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_NORMAL,                           // Event BUBBLE_DENY
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_NORMAL,                           // Event WINDOW_CHANGE
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    { // STATE_BROWSER_FULLSCREEN_NO_CHROME:
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event TOGGLE_FULLSCREEN_CHROME
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event TAB_FULLSCREEN_TRUE
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event TAB_FULLSCREEN_FALSE
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event METRO_SNAP_FALSE
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event BUBBLE_ALLOW
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event BUBBLE_DENY
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event WINDOW_CHANGE
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_BROWSER_FULLSCREEN_WITH_CHROME:
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event TOGGLE_FULLSCREEN
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN_CHROME,    // Event TAB_FULLSCREEN_TRUE
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event TAB_FULLSCREEN_FALSE
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event METRO_SNAP_TRUE
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event METRO_SNAP_FALSE
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event BUBBLE_ALLOW
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event BUBBLE_DENY
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event WINDOW_CHANGE
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    },
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    { // STATE_METRO_SNAP:
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event TOGGLE_FULLSCREEN
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_METRO_SNAP,                       // Event TOGGLE_FULLSCREEN_CHROME
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event TAB_FULLSCREEN_TRUE
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event TAB_FULLSCREEN_FALSE
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_NORMAL,                           // Event METRO_SNAP_FALSE
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_METRO_SNAP,                       // Event BUBBLE_EXIT_LINK
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_METRO_SNAP,                       // Event BUBBLE_ALLOW
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_METRO_SNAP,                       // Event BUBBLE_DENY
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event WINDOW_CHANGE
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    { // STATE_TAB_FULLSCREEN:
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_FULLSCREEN,                   // Event TAB_FULLSCREEN_TRUE
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TAB_FULLSCREEN_FALSE
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_FULLSCREEN,                   // Event METRO_SNAP_FALSE
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_FULLSCREEN,                   // Event BUBBLE_ALLOW
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_DENY
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_FULLSCREEN,                   // Event WINDOW_CHANGE
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    { // STATE_TAB_BROWSER_FULLSCREEN:
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event TAB_FULLSCREEN_TRUE
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event TAB_FULLSCREEN_FALSE
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event METRO_SNAP_FALSE
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event BUBBLE_EXIT_LINK
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event BUBBLE_ALLOW
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event BUBBLE_DENY
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event WINDOW_CHANGE
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_TAB_BROWSER_FULLSCREEN_CHROME:
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN_CHROME,    // Event TAB_FULLSCREEN_TRUE
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event TAB_FULLSCREEN_FALSE
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN_CHROME,    // Event METRO_SNAP_FALSE
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event BUBBLE_EXIT_LINK
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN_CHROME,    // Event BUBBLE_ALLOW
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event BUBBLE_DENY
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN_CHROME,    // Event WINDOW_CHANGE
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    },
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_TO_NORMAL:
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event TOGGLE_FULLSCREEN_CHROME
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // TODO(scheib) Should be a route back to TAB. http://crbug.com/154196
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TAB_FULLSCREEN_TRUE
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event TAB_FULLSCREEN_FALSE
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_NORMAL,                        // Event METRO_SNAP_FALSE
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_ALLOW
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_DENY
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_NORMAL,                           // Event WINDOW_CHANGE
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_TO_BROWSER_FULLSCREEN_NO_CHROME:
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TOGGLE_FULLSCREEN
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event TOGGLE_FULLSCREEN_CHROME
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // TODO(scheib) Should be a route to TAB_BROWSER http://crbug.com/154196
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TAB_FULLSCREEN_TRUE
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TAB_FULLSCREEN_FALSE
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event METRO_SNAP_FALSE
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // Mac window reports fullscreen immediately and an exit triggers exit.
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event BUBBLE_EXIT_LINK
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event BUBBLE_ALLOW
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event BUBBLE_DENY
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_BROWSER_FULLSCREEN_NO_CHROME,     // Event WINDOW_CHANGE
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME:
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TOGGLE_FULLSCREEN
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // TODO(scheib) Should be a route to TAB_BROWSER http://crbug.com/154196
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TAB_BROWSER_FULLSCREEN,           // Event TAB_FULLSCREEN_TRUE
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event TAB_FULLSCREEN_FALSE
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event METRO_SNAP_TRUE
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event METRO_SNAP_FALSE
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event BUBBLE_ALLOW
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME,// Event BUBBLE_DENY
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_BROWSER_FULLSCREEN_WITH_CHROME,   // Event WINDOW_CHANGE
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    },
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    { // STATE_TO_TAB_FULLSCREEN:
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // TODO(scheib) Should be a route to TAB_BROWSER http://crbug.com/154196
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event TOGGLE_FULLSCREEN
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TOGGLE_FULLSCREEN_CHROME
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event TAB_FULLSCREEN_TRUE
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // Mac runs as expected due to a forced NotifyTabOfExitIfNecessary();
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event TAB_FULLSCREEN_FALSE
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // TODO(scheib) Should be a route back to NORMAL. http://crbug.com/154196
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_BROWSER_FULLSCREEN_NO_CHROME,  // Event TAB_FULLSCREEN_FALSE
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_METRO_SNAP,                       // Event METRO_SNAP_TRUE
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event METRO_SNAP_FALSE
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // Mac window reports fullscreen immediately and an exit triggers exit.
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_EXIT_LINK
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event BUBBLE_EXIT_LINK
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event BUBBLE_ALLOW
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      // Mac window reports fullscreen immediately and an exit triggers exit.
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_NORMAL,                        // Event BUBBLE_DENY
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      STATE_TO_TAB_FULLSCREEN,                // Event BUBBLE_DENY
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      STATE_TAB_FULLSCREEN,                   // Event WINDOW_CHANGE
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    },
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
202a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  COMPILE_ASSERT(sizeof(transition_table_data) == sizeof(transition_table_),
203a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                 transition_table_incorrect_size);
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  memcpy(transition_table_, transition_table_data,
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         sizeof(transition_table_data));
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Verify that transition_table_ has been completely defined.
208a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  for (int source = 0; source < NUM_STATES; ++source) {
209a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int event = 0; event < NUM_EVENTS; ++event) {
210a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      EXPECT_NE(transition_table_[source][event], STATE_INVALID);
211a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      EXPECT_GE(transition_table_[source][event], 0);
212a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      EXPECT_LT(transition_table_[source][event], NUM_STATES);
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Copy transition_table_ data into state_transitions_ table.
217a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  for (int source = 0; source < NUM_STATES; ++source) {
218a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int event = 0; event < NUM_EVENTS; ++event) {
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (ShouldSkipStateAndEventPair(static_cast<State>(source),
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      static_cast<Event>(event)))
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        continue;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      State destination = transition_table_[source][event];
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      state_transitions_[source][destination].event = static_cast<Event>(event);
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      state_transitions_[source][destination].state = destination;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      state_transitions_[source][destination].distance = 1;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FullscreenControllerStateTest::~FullscreenControllerStateTest() {
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* FullscreenControllerStateTest::GetStateString(State state) {
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (state) {
236a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_NORMAL);
237a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_BROWSER_FULLSCREEN_NO_CHROME);
238a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_BROWSER_FULLSCREEN_WITH_CHROME);
239a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_METRO_SNAP);
240a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TAB_FULLSCREEN);
241a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TAB_BROWSER_FULLSCREEN);
242a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TAB_BROWSER_FULLSCREEN_CHROME);
243a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TO_NORMAL);
244a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TO_BROWSER_FULLSCREEN_NO_CHROME);
245a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME);
246a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_TO_TAB_FULLSCREEN);
247a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(STATE_INVALID);
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    default:
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NOTREACHED() << "No string for state " << state;
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return "State-Unknown";
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* FullscreenControllerStateTest::GetEventString(Event event) {
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (event) {
257a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(TOGGLE_FULLSCREEN);
258a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(TOGGLE_FULLSCREEN_CHROME);
259a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(TAB_FULLSCREEN_TRUE);
260a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(TAB_FULLSCREEN_FALSE);
261a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(METRO_SNAP_TRUE);
262a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(METRO_SNAP_FALSE);
263a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(BUBBLE_EXIT_LINK);
264a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(BUBBLE_ALLOW);
265a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(BUBBLE_DENY);
266a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(WINDOW_CHANGE);
267a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    ENUM_TO_STRING(EVENT_INVALID);
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    default:
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NOTREACHED() << "No string for event " << event;
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return "Event-Unknown";
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// static
275a3f7b4e666c476898878fa745f637129375cd889Ben Murdochbool FullscreenControllerStateTest::IsWindowFullscreenStateChangedReentrant() {
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(TOOLKIT_VIEWS)
277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#else
279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return false;
280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif
281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// static
284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool FullscreenControllerStateTest::IsPersistentState(State state) {
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  switch (state) {
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_NORMAL:
287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_BROWSER_FULLSCREEN_NO_CHROME:
288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_BROWSER_FULLSCREEN_WITH_CHROME:
289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_METRO_SNAP:
290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TAB_FULLSCREEN:
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TAB_BROWSER_FULLSCREEN:
292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TAB_BROWSER_FULLSCREEN_CHROME:
293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return true;
294a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TO_NORMAL:
296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TO_BROWSER_FULLSCREEN_NO_CHROME:
297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME:
298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    case STATE_TO_TAB_FULLSCREEN:
299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return false;
300a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    default:
302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      NOTREACHED();
303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return false;
304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
306c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerStateTest::TransitionToState(State final_state) {
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int max_steps = NUM_STATES;
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (max_steps-- && TransitionAStepTowardState(final_state))
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    continue;
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_GE(max_steps, 0) << "TransitionToState was unable to achieve desired "
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "target state. TransitionAStepTowardState iterated too many times."
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << GetAndClearDebugLog();
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(final_state, state_) << "TransitionToState was unable to achieve "
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << "desired target state. TransitionAStepTowardState returned false."
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << GetAndClearDebugLog();
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerStateTest::TransitionAStepTowardState(
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    State destination_state) {
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State source_state = state_;
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (source_state == destination_state)
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StateTransitionInfo next = NextTransitionInShortestPath(source_state,
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                          destination_state,
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                          NUM_STATES);
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (next.state == STATE_INVALID) {
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOTREACHED() << "TransitionAStepTowardState unable to transition. "
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << "NextTransitionInShortestPath("
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetStateString(source_state) << ", "
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetStateString(destination_state) << ") returned STATE_INVALID."
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetAndClearDebugLog();
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return InvokeEvent(next.event);
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* FullscreenControllerStateTest::GetWindowStateString() {
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerStateTest::InvokeEvent(Event event) {
345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!fullscreen_notification_observer_.get()) {
346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Start observing NOTIFICATION_FULLSCREEN_CHANGED. Construct the
347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // notification observer here instead of in
348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // FullscreenControllerStateTest::FullscreenControllerStateTest() so that we
349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // listen to notifications on the proper thread.
350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    fullscreen_notification_observer_.reset(
351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        new FullscreenNotificationObserver());
352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
353c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State source_state = state_;
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State next_state = transition_table_[source_state][event];
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(ShouldSkipStateAndEventPair(source_state, event))
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      << GetAndClearDebugLog();
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When simulating reentrant window change calls, expect the next state
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // automatically.
362a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (IsWindowFullscreenStateChangedReentrant())
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    next_state = transition_table_[next_state][WINDOW_CHANGE];
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  debugging_log_ << "  InvokeEvent(" << std::left
366a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      << std::setw(kMaxStateNameLength) << GetEventString(event)
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << ") to "
368a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      << std::setw(kMaxStateNameLength) << GetStateString(next_state);
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  state_ = next_state;
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (event) {
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case TOGGLE_FULLSCREEN:
374a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetFullscreenController()->ToggleBrowserFullscreenMode();
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
376a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case TOGGLE_FULLSCREEN_CHROME:
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
3797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      if (chrome::mac::SupportsSystemFullscreen()) {
380a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        GetFullscreenController()->ToggleBrowserFullscreenWithChrome();
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        break;
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED() << GetAndClearDebugLog();
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
386a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case TAB_FULLSCREEN_TRUE:
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case TAB_FULLSCREEN_FALSE: {
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content::WebContents* const active_tab =
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          GetBrowser()->tab_strip_model()->GetActiveWebContents();
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetFullscreenController()->
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          ToggleFullscreenModeForTab(active_tab, event == TAB_FULLSCREEN_TRUE);
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // Activating/Deactivating tab fullscreen on a captured tab should not
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // evoke a state change in the browser window.
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (active_tab->GetCapturerCount() > 0)
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        state_ = source_state;
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
399a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case METRO_SNAP_TRUE:
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetFullscreenController()->SetMetroSnapMode(true);
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED() << GetAndClearDebugLog();
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
407a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case METRO_SNAP_FALSE:
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetFullscreenController()->SetMetroSnapMode(false);
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED() << GetAndClearDebugLog();
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
415a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case BUBBLE_EXIT_LINK:
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GetFullscreenController()->ExitTabOrBrowserFullscreenToPreviousState();
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
419a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case BUBBLE_ALLOW:
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GetFullscreenController()->OnAcceptFullscreenPermission();
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
423a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case BUBBLE_DENY:
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GetFullscreenController()->OnDenyFullscreenPermission();
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
427a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case WINDOW_CHANGE:
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ChangeWindowFullscreenState();
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
431a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    default:
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NOTREACHED() << "InvokeEvent needs a handler for event "
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          << GetEventString(event) << GetAndClearDebugLog();
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return false;
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetWindowStateString())
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    debugging_log_ << " Window state now " << GetWindowStateString() << "\n";
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    debugging_log_ << "\n";
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  MaybeWaitForNotification();
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VerifyWindowState();
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerStateTest::VerifyWindowState() {
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (state_) {
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_NORMAL:
452a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
453a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_FALSE,
454a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_FALSE,
455a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_FALSE,
456a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_BROWSER_FULLSCREEN_NO_CHROME:
459a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
460a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_TRUE,
461a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
462a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_FALSE,
463a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case STATE_BROWSER_FULLSCREEN_WITH_CHROME:
466a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_TRUE,
467a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_FALSE,
468a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
469a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_FALSE,
470a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_METRO_SNAP:
473a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_NO_EXPECTATION,
474a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_NO_EXPECTATION,
475a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_NO_EXPECTATION,
476a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_NO_EXPECTATION,
477a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_TRUE);
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_TAB_FULLSCREEN:
480a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
481a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_TRUE,
482a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_FALSE,
483a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_TRUE,
484a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_TAB_BROWSER_FULLSCREEN:
487a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
488a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_TRUE,
489a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
490a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_TRUE,
491a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case STATE_TAB_BROWSER_FULLSCREEN_CHROME:
494a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
495a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_TRUE,
496a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
497a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_TRUE,
498a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_TO_NORMAL:
501a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
502a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_FALSE,
503a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_NO_EXPECTATION,
504a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_NO_EXPECTATION,
505a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
507a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_TO_BROWSER_FULLSCREEN_NO_CHROME:
509a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_FALSE,
510a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_TRUE,
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_MACOSX)
512a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
514a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_FALSE,
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
516a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_NO_EXPECTATION,
517a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
519a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME:
521a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_TRUE,
522a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_FALSE,
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX)
524a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_TRUE,
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
526a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_FALSE,
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
528a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_NO_EXPECTATION,
529a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
531a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case STATE_TO_TAB_FULLSCREEN:
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_MACOSX)
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // TODO(scheib) InPresentationMode returns false when invoking events:
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // TAB_FULLSCREEN_TRUE, TOGGLE_FULLSCREEN. http://crbug.com/156645
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // It may be that a new testing state TO_TAB_BROWSER_FULLSCREEN
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // would help work around this http://crbug.com/154196
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Test with: STATE_TO_TAB_FULLSCREEN__TOGGLE_FULLSCREEN
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      //
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // EXPECT_TRUE(GetBrowser()->window()->InPresentationMode())
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      //     << GetAndClearDebugLog();
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
543a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      VerifyWindowStateExpectations(FULLSCREEN_WITH_CHROME_NO_EXPECTATION,
544a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_WITHOUT_CHROME_NO_EXPECTATION,
545a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_BROWSER_FALSE,
546a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    FULLSCREEN_FOR_TAB_TRUE,
547a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch                                    IN_METRO_SNAP_FALSE);
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
549a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    default:
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NOTREACHED() << GetAndClearDebugLog();
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void FullscreenControllerStateTest::MaybeWaitForNotification() {
556c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We should get a fullscreen notification each time we get to a new
557c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // persistent state. If we don't get a notification, the test will
558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // fail by timing out.
559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (state_ != last_notification_received_state_ &&
560c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      IsPersistentState(state_)) {
561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    fullscreen_notification_observer_->Wait();
562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    last_notification_received_state_ = state_;
563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    fullscreen_notification_observer_.reset(
564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        new FullscreenNotificationObserver());
565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
566c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
567c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerStateTest::TestTransitionsForEachState() {
569a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  for (int source_int = 0; source_int < NUM_STATES; ++source_int) {
570a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int event1_int = 0; event1_int < NUM_EVENTS; ++event1_int) {
571c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      State state = static_cast<State>(source_int);
572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      Event event1 = static_cast<Event>(event1_int);
573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      // Early out if skipping all tests for this state, reduces log noise.
575c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      if (ShouldSkipTest(state, event1))
576c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        continue;
577c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
578a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      for (int event2_int = 0; event2_int < NUM_EVENTS; ++event2_int) {
579a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch        for (int event3_int = 0; event3_int < NUM_EVENTS; ++event3_int) {
580c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          Event event2 = static_cast<Event>(event2_int);
581c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          Event event3 = static_cast<Event>(event3_int);
582c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
583c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          // Test each state and each event.
584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          ASSERT_NO_FATAL_FAILURE(TestStateAndEvent(state, event1))
585c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              << GetAndClearDebugLog();
586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          // Then, add an additional event to the sequence.
588c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          if (ShouldSkipStateAndEventPair(state_, event2))
589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            continue;
590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          ASSERT_TRUE(InvokeEvent(event2)) << GetAndClearDebugLog();
591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          // Then, add an additional event to the sequence.
593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          if (ShouldSkipStateAndEventPair(state_, event3))
594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            continue;
595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          ASSERT_TRUE(InvokeEvent(event3)) << GetAndClearDebugLog();
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FullscreenControllerStateTest::StateTransitionInfo
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FullscreenControllerStateTest::NextTransitionInShortestPath(
604a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    State source,
605a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    State destination,
606a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    int search_limit) {
607a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (search_limit <= 0)
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return StateTransitionInfo();  // Return a default (invalid) state.
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (state_transitions_[source][destination].state == STATE_INVALID) {
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Don't know the next state yet, do a depth first search.
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    StateTransitionInfo result;
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Consider all states reachable via each event from the source state.
615a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int event_int = 0; event_int < NUM_EVENTS; ++event_int) {
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Event event = static_cast<Event>(event_int);
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      State next_state_candidate = transition_table_[source][event];
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (ShouldSkipStateAndEventPair(source, event))
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        continue;
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      // Recurse.
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      StateTransitionInfo candidate = NextTransitionInShortestPath(
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          next_state_candidate, destination, search_limit - 1);
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (candidate.distance + 1 < result.distance) {
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        result.event = event;
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        result.state = next_state_candidate;
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        result.distance = candidate.distance + 1;
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Cache result so that a search is not required next time.
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    state_transitions_[source][destination] = result;
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return state_transitions_[source][destination];
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string FullscreenControllerStateTest::GetAndClearDebugLog() {
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  debugging_log_ << "(End of Debugging Log)\n";
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string output_log = "\nDebugging Log:\n" + debugging_log_.str();
643c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  debugging_log_.str(std::string());
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return output_log;
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerStateTest::ShouldSkipStateAndEventPair(State state,
6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                                Event event) {
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(scheib) Toggling Tab fullscreen while pending Tab or
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Browser fullscreen is broken currently http://crbug.com/154196
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if ((state == STATE_TO_BROWSER_FULLSCREEN_NO_CHROME ||
6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       state == STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME ||
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       state == STATE_TO_TAB_FULLSCREEN) &&
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (event == TAB_FULLSCREEN_TRUE || event == TAB_FULLSCREEN_FALSE))
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (state == STATE_TO_NORMAL && event == TAB_FULLSCREEN_TRUE)
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Skip metro snap state and events when not on windows.
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_WIN)
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (state == STATE_METRO_SNAP ||
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      event == METRO_SNAP_TRUE ||
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      event == METRO_SNAP_FALSE)
6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Skip Mac Lion Fullscreen state and events when not on OSX 10.7+.
6687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!SupportsMacSystemFullscreen()) {
6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (state == STATE_BROWSER_FULLSCREEN_WITH_CHROME ||
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        state == STATE_TAB_BROWSER_FULLSCREEN_CHROME ||
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        state == STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME ||
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        event == TOGGLE_FULLSCREEN_CHROME) {
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return true;
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
680c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool FullscreenControllerStateTest::ShouldSkipTest(State state, Event event) {
6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Quietly skip metro snap tests when not on windows.
6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_WIN)
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (state == STATE_METRO_SNAP ||
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      event == METRO_SNAP_TRUE ||
6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      event == METRO_SNAP_FALSE) {
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    debugging_log_ << "\nSkipping metro snap test on non-Windows.\n";
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Quietly skip Mac Lion Fullscreen tests when not on OSX 10.7+.
6927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!SupportsMacSystemFullscreen()) {
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (state == STATE_BROWSER_FULLSCREEN_WITH_CHROME ||
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        event == TOGGLE_FULLSCREEN_CHROME) {
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      debugging_log_ << "\nSkipping Lion Fullscreen test on non-OSX 10.7+.\n";
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return true;
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When testing reentrancy there are states the fullscreen controller
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be unable to remain in, as they will progress due to the
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // reentrant window change call. Skip states that will be instantly
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // exited by the reentrant call.
704a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (IsWindowFullscreenStateChangedReentrant() &&
705a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      (transition_table_[state][WINDOW_CHANGE] != state)) {
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    debugging_log_ << "\nSkipping reentrant test for transitory source state "
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetStateString(state) << ".\n";
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (ShouldSkipStateAndEventPair(state, event)) {
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    debugging_log_ << "\nSkipping test due to ShouldSkipStateAndEventPair("
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetStateString(state) << ", "
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetEventString(event) << ").\n";
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LOG(INFO) << "Skipping test due to ShouldSkipStateAndEventPair("
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetStateString(state) << ", "
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        << GetEventString(event) << ").";
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerStateTest::TestStateAndEvent(State state,
725c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                                      Event event) {
726c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (ShouldSkipTest(state, event))
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  debugging_log_ << "\nTest transition from state "
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << GetStateString(state)
731a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      << (IsWindowFullscreenStateChangedReentrant() ?
732a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch          " with reentrant calls.\n" : ".\n");
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
734a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  // Spaced out text to line up with columns printed in InvokeEvent().
735a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  debugging_log_ << "First,                                               from "
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << GetStateString(state_) << "\n";
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(TransitionToState(state))
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      << GetAndClearDebugLog();
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  debugging_log_ << " Then,\n";
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(InvokeEvent(event)) << GetAndClearDebugLog();
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
744a3f7b4e666c476898878fa745f637129375cd889Ben Murdochvoid FullscreenControllerStateTest::VerifyWindowStateExpectations(
745a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    FullscreenWithChromeExpectation fullscreen_with_chrome,
746a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    FullscreenWithoutChromeExpectation fullscreen_without_chrome,
747a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    FullscreenForBrowserExpectation fullscreen_for_browser,
748a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    FullscreenForTabExpectation fullscreen_for_tab,
749a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    InMetroSnapExpectation in_metro_snap) {
750a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#if defined(OS_MACOSX)
751a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (fullscreen_with_chrome != FULLSCREEN_WITH_CHROME_NO_EXPECTATION) {
752a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    EXPECT_EQ(GetBrowser()->window()->IsFullscreenWithChrome(),
753a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch              !!fullscreen_with_chrome) << GetAndClearDebugLog();
754a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  }
755a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (fullscreen_without_chrome != FULLSCREEN_WITHOUT_CHROME_NO_EXPECTATION) {
756a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    EXPECT_EQ(GetBrowser()->window()->IsFullscreenWithoutChrome(),
757a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch              !!fullscreen_without_chrome) << GetAndClearDebugLog();
758a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  }
759a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#endif
760a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (fullscreen_for_browser != FULLSCREEN_FOR_BROWSER_NO_EXPECTATION) {
761a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    EXPECT_EQ(GetFullscreenController()->IsFullscreenForBrowser(),
762a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch              !!fullscreen_for_browser) << GetAndClearDebugLog();
763a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  }
764a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (fullscreen_for_tab != FULLSCREEN_FOR_TAB_NO_EXPECTATION) {
765a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    EXPECT_EQ(GetFullscreenController()->IsWindowFullscreenForTabOrPending(),
766a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch              !!fullscreen_for_tab) << GetAndClearDebugLog();
767a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  }
768a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  if (in_metro_snap != IN_METRO_SNAP_NO_EXPECTATION) {
769a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    EXPECT_EQ(GetFullscreenController()->IsInMetroSnapMode(),
770a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch              !!in_metro_snap) << GetAndClearDebugLog();
771a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  }
772a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch}
773a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FullscreenController* FullscreenControllerStateTest::GetFullscreenController() {
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return GetBrowser()->fullscreen_controller();
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string FullscreenControllerStateTest::GetTransitionTableAsString() const {
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::ostringstream output;
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  output << "transition_table_[NUM_STATES = " << NUM_STATES
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      << "][NUM_EVENTS = " << NUM_EVENTS
7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      << "] =\n";
783a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  for (int state_int = 0; state_int < NUM_STATES; ++state_int) {
7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    State state = static_cast<State>(state_int);
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    output << "    { // " << GetStateString(state) << ":\n";
786a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int event_int = 0; event_int < NUM_EVENTS; ++event_int) {
7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Event event = static_cast<Event>(event_int);
7882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      output << "      "
789a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch          << std::left << std::setw(kMaxStateNameLength+1)
7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          << std::string(GetStateString(transition_table_[state][event])) + ","
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          << "// Event "
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          << GetEventString(event) << "\n";
7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    output << "    },\n";
7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  output << "  };\n";
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return output.str();
7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::string FullscreenControllerStateTest::GetStateTransitionsAsString() const {
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::ostringstream output;
8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  output << "state_transitions_[NUM_STATES = " << NUM_STATES
8032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      << "][NUM_STATES = " << NUM_STATES << "] =\n";
804a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  for (int state1_int = 0; state1_int < NUM_STATES; ++state1_int) {
8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    State state1 = static_cast<State>(state1_int);
8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    output << "{ // " << GetStateString(state1) << ":\n";
807a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch    for (int state2_int = 0; state2_int < NUM_STATES; ++state2_int) {
8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      State state2 = static_cast<State>(state2_int);
809a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch      const StateTransitionInfo& info = state_transitions_[state1][state2];
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      output << "  { "
811a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch        << std::left << std::setw(kMaxStateNameLength+1)
8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << std::string(GetEventString(info.event)) + ","
813a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch        << std::left << std::setw(kMaxStateNameLength+1)
8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << std::string(GetStateString(info.state)) + ","
8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << std::right << std::setw(2)
8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << info.distance
8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << " }, // "
8182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        << GetStateString(state2) << "\n";
8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    output << "},\n";
8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  output << "};";
8232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return output.str();
8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
825