summaryrefslogtreecommitdiffstats
path: root/chrome/test/reliability/automated_ui_test_interactive_test.cc
blob: 04c09690440ab8f7c21a47491736c9249f2fc4e4 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/reliability/automated_ui_test_base.h"
#include "chrome/test/ui/ui_test.h"

TEST_F(AutomatedUITestBase, DragOut) {
  NewTab();
  NewTab();
  ASSERT_TRUE(active_browser()->WaitForTabCountToBecome(3));
  base::PlatformThread::Sleep(TestTimeouts::action_timeout());
  ASSERT_TRUE(DragTabOut());
  int window_count;
  ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
  ASSERT_EQ(2, window_count);
}

TEST_F(AutomatedUITestBase, DragLeftRight) {
  NewTab();
  NewTab();
  ASSERT_TRUE(active_browser()->WaitForTabCountToBecome(3));
  // TODO(phajdan.jr): We need a WaitForTabstripAnimationsToEnd() function.
  // Every sleep in this file should be replaced with it.
  const base::TimeDelta kDelay = TestTimeouts::action_timeout();
  base::PlatformThread::Sleep(kDelay);

  scoped_refptr<TabProxy> dragged_tab(active_browser()->GetActiveTab());
  int tab_index;
  ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index));
  EXPECT_EQ(2, tab_index);

  // Drag the active tab to left. Now it should be the middle tab.
  ASSERT_TRUE(DragActiveTab(false));
  // We wait for the animation to be over.
  base::PlatformThread::Sleep(kDelay);
  ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index));
  EXPECT_EQ(1, tab_index);

  // Drag the active tab to left. Now it should be the leftmost tab.
  ASSERT_TRUE(DragActiveTab(false));
  base::PlatformThread::Sleep(kDelay);
  ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index));
  EXPECT_EQ(0, tab_index);

  // Drag the active tab to left. It should fail since the active tab is
  // already the leftmost tab.
  ASSERT_FALSE(DragActiveTab(false));

  // Drag the active tab to right. Now it should be the middle tab.
  ASSERT_TRUE(DragActiveTab(true));
  base::PlatformThread::Sleep(kDelay);
  ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index));
  EXPECT_EQ(1, tab_index);

  // Drag the active tab to right. Now it should be the rightmost tab.
  ASSERT_TRUE(DragActiveTab(true));
  base::PlatformThread::Sleep(kDelay);
  ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index));
  EXPECT_EQ(2, tab_index);

  // Drag the active tab to right. It should fail since the active tab is
  // already the rightmost tab.
  ASSERT_FALSE(DragActiveTab(true));
}