• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/app/chrome_command_ids.h"
6 #include "chrome/test/automation/browser_proxy.h"
7 #include "chrome/test/automation/tab_proxy.h"
8 #include "chrome/test/ui/ui_test.h"
9 #include "net/test/test_server.h"
10 
11 class FindInPageControllerTest : public UITest {
12  public:
FindInPageControllerTest()13   FindInPageControllerTest() {
14     show_window_ = true;
15   }
16 };
17 
18 const std::string kSimplePage = "404_is_enough_for_us.html";
19 
20 #if !defined(OS_WIN)
21 // Has never been enabled on other platforms http://crbug.com/45753
22 #define FindMovesOnTabClose_Issue1343052 \
23     DISABLED_FindMovesOnTabClose_Issue1343052
24 #endif
25 // The find window should not change its location just because we open and close
26 // a new tab.
TEST_F(FindInPageControllerTest,FindMovesOnTabClose_Issue1343052)27 TEST_F(FindInPageControllerTest, FindMovesOnTabClose_Issue1343052) {
28   net::TestServer test_server(net::TestServer::TYPE_HTTP,
29                               FilePath(FILE_PATH_LITERAL("chrome/test/data")));
30   ASSERT_TRUE(test_server.Start());
31 
32   GURL url = test_server.GetURL(kSimplePage);
33   scoped_refptr<TabProxy> tabA(GetActiveTab());
34   ASSERT_TRUE(tabA.get());
35   ASSERT_TRUE(tabA->NavigateToURL(url));
36   WaitUntilTabCount(1);
37 
38   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
39   ASSERT_TRUE(browser.get() != NULL);
40 
41   // Toggle the bookmark bar state.
42   EXPECT_TRUE(browser->ApplyAccelerator(IDC_SHOW_BOOKMARK_BAR));
43   EXPECT_TRUE(WaitForBookmarkBarVisibilityChange(browser.get(), true));
44 
45   // Open the Find window and wait for it to animate.
46   EXPECT_TRUE(browser->OpenFindInPage());
47   EXPECT_TRUE(WaitForFindWindowVisibilityChange(browser.get(), true));
48 
49   // Find its location.
50   int x = -1, y = -1;
51   EXPECT_TRUE(browser->GetFindWindowLocation(&x, &y));
52 
53   // Open another tab (tab B).
54   EXPECT_TRUE(browser->AppendTab(url));
55   scoped_refptr<TabProxy> tabB(GetActiveTab());
56   ASSERT_TRUE(tabB.get());
57 
58   // Close tab B.
59   EXPECT_TRUE(tabB->Close(true));
60 
61   // See if the Find window has moved.
62   int new_x = -1, new_y = -1;
63   EXPECT_TRUE(browser->GetFindWindowLocation(&new_x, &new_y));
64 
65   EXPECT_EQ(x, new_x);
66   EXPECT_EQ(y, new_y);
67 
68   // Now reset the bookmark bar state and try the same again.
69   EXPECT_TRUE(browser->ApplyAccelerator(IDC_SHOW_BOOKMARK_BAR));
70   EXPECT_TRUE(WaitForBookmarkBarVisibilityChange(browser.get(), false));
71 
72   // Bookmark bar has moved, reset our coordinates.
73   EXPECT_TRUE(browser->GetFindWindowLocation(&x, &y));
74 
75   // Open another tab (tab C).
76   EXPECT_TRUE(browser->AppendTab(url));
77   scoped_refptr<TabProxy> tabC(GetActiveTab());
78   ASSERT_TRUE(tabC.get());
79 
80   // Close it.
81   EXPECT_TRUE(tabC->Close(true));
82 
83   // See if the Find window has moved.
84   EXPECT_TRUE(browser->GetFindWindowLocation(&new_x, &new_y));
85 
86   EXPECT_EQ(x, new_x);
87   EXPECT_EQ(y, new_y);
88 }
89