summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/constrained_window_tab_helper_unittest.cc
blob: a03797fc1c674db6844133c367d9d60652cec9c4 (plain)
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
// 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.

#include "chrome/browser/ui/constrained_window.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"

using content::BrowserThread;

class ConstrainedWindowTabHelperUnit : public TabContentsTestHarness {
 public:
  ConstrainedWindowTabHelperUnit()
      : TabContentsTestHarness(),
        ui_thread_(BrowserThread::UI, &message_loop_) {
  }

 private:
  content::TestBrowserThread ui_thread_;
};

class ConstrainedWindowCloseTest : public ConstrainedWindow {
 public:
  explicit ConstrainedWindowCloseTest(TabContents* tab_contents)
      : tab_contents_(tab_contents) {
  }

  virtual void ShowConstrainedWindow() {}
  virtual void FocusConstrainedWindow() {}
  virtual ~ConstrainedWindowCloseTest() {}

  virtual void CloseConstrainedWindow() {
    tab_contents_->constrained_window_tab_helper()->WillClose(this);
    close_count++;
  }

  int close_count;
  TabContents* tab_contents_;
};

TEST_F(ConstrainedWindowTabHelperUnit, ConstrainedWindows) {
  ConstrainedWindowCloseTest window(tab_contents());
  window.close_count = 0;

  const int kWindowCount = 4;
  for (int i = 0; i < kWindowCount; i++) {
    tab_contents()->constrained_window_tab_helper()->AddConstrainedDialog(
        &window);
  }
  EXPECT_EQ(window.close_count, 0);
  tab_contents()->constrained_window_tab_helper()->CloseConstrainedWindows();
  EXPECT_EQ(window.close_count, kWindowCount);
}