Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2012 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 <mshtmcid.h>
      6 #include <string>
      7 
      8 #include "base/file_util.h"
      9 #include "base/strings/utf_string_conversions.h"
     10 #include "base/test/test_file_util.h"
     11 #include "base/win/scoped_bstr.h"
     12 #include "base/win/scoped_variant.h"
     13 #include "base/win/windows_version.h"
     14 #include "chrome/common/url_constants.h"
     15 #include "chrome_frame/test/chrome_frame_test_utils.h"
     16 #include "chrome_frame/test/chrome_frame_ui_test_utils.h"
     17 #include "chrome_frame/test/mock_ie_event_sink_actions.h"
     18 #include "chrome_frame/test/mock_ie_event_sink_test.h"
     19 #include "chrome_frame/test/simulate_input.h"
     20 
     21 #include "testing/gmock_mutant.h"
     22 
     23 using testing::_;
     24 using testing::InSequence;
     25 using testing::StrCaseEq;
     26 using testing::StrEq;
     27 
     28 namespace chrome_frame_test {
     29 
     30 // This parameterized test fixture uses the MockIEEventSink and is used by
     31 // UI-related tests.
     32 class FullTabUITest : public MockIEEventSinkTest,
     33                       public testing::TestWithParam<CFInvocation> {
     34  public:
     35   FullTabUITest() {}
     36 
     37   virtual void SetUp() {
     38     ResetKeyState();
     39 
     40     // These are UI-related tests, so we do not care about the exact requests
     41     // and navigations that occur.
     42     server_mock_.ExpectAndServeAnyRequests(GetParam());
     43     ie_mock_.ExpectAnyNavigations();
     44   }
     45 
     46   virtual void TearDown() {
     47     ResetKeyState();
     48   }
     49 
     50   void ResetKeyState() {
     51     // Call this to reset the state of any current keyboard modifiers, as it has
     52     // been observed that these tests can leave the desktop in an invalid state
     53     // (e.g. thinking that the Ctrl key is held down). Send F23 as that is
     54     // particularly unlikely to be used by any real application.
     55     simulate_input::SendMnemonic(
     56         VK_F23,
     57         simulate_input::CONTROL | simulate_input::SHIFT | simulate_input::ALT,
     58         false,
     59         false,
     60         simulate_input::KEY_UP);
     61   }
     62 };
     63 
     64 // Instantiate each test case for the IE case and for CF meta tag case.
     65 // It does not seem too useful to also run the CF http header case since these
     66 // are UI, not navigation tests.
     67 INSTANTIATE_TEST_CASE_P(IE, FullTabUITest,
     68                         testing::Values(CFInvocation::None()));
     69 INSTANTIATE_TEST_CASE_P(CF, FullTabUITest,
     70                         testing::Values(CFInvocation::MetaTag()));
     71 
     72 // Tests keyboard input.
     73 TEST_P(FullTabUITest, KeyboardInput) {
     74   if (!GetParam().invokes_cf()) {
     75     LOG(ERROR) << "Test not implemented for this configuration.";
     76     return;
     77   }
     78   std::wstring key_event_url = GetTestUrl(L"keyevent.html");
     79 
     80   static const char input[] = "chrome";
     81   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(), StrEq(key_event_url)))
     82       .WillOnce(PostKeyMessagesToRenderer(&ie_mock_, input));
     83 
     84   EXPECT_CALL(ie_mock_, OnMessage(StrCaseEq(UTF8ToWide(input)), _, _))
     85       .WillOnce(CloseBrowserMock(&ie_mock_));
     86 
     87   LaunchIEAndNavigate(key_event_url);
     88 }
     89 
     90 // Tests keyboard shortcuts for back and forward.
     91 // http://code.google.com/p/chromium/issues/detail?id=114058
     92 TEST_P(FullTabUITest, DISABLED_KeyboardBackForward) {
     93   if (IsWorkstationLocked()) {
     94     LOG(ERROR) << "This test cannot be run in a locked workstation.";
     95     return;
     96   }
     97 
     98   std::wstring page1 = GetSimplePageUrl();
     99   std::wstring page2 = GetLinkPageUrl();
    100   bool in_cf = GetParam().invokes_cf();
    101   InSequence expect_in_sequence_for_scope;
    102 
    103   // This test performs the following steps.
    104   // 1. Launches IE and navigates to page1
    105   // 2. It then navigates to page2
    106   // 3. Sends the VK_BACK keystroke to IE, which should navigate back to
    107   //    page 1
    108   // 4. Sends the Shift + VK_BACK keystroke to IE which should navigate
    109   //    forward to page2
    110   EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page1)))
    111       .WillOnce(Navigate(&ie_mock_, page2));
    112 
    113   short bkspace = VkKeyScanA(VK_BACK);  // NOLINT
    114   EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page2)))
    115       .WillOnce(testing::DoAll(
    116           SetFocusToRenderer(&ie_mock_),
    117           DelaySendScanCode(&loop_,
    118                             base::TimeDelta::FromSeconds(1),
    119                             bkspace,
    120                             simulate_input::NONE)));
    121 
    122   EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page1)))
    123       .WillOnce(testing::DoAll(
    124           SetFocusToRenderer(&ie_mock_),
    125           DelaySendScanCode(&loop_,
    126                             base::TimeDelta::FromSeconds(1),
    127                             bkspace,
    128                             simulate_input::SHIFT)));
    129 
    130   EXPECT_CALL(ie_mock_, OnLoad(in_cf, StrEq(page2)))
    131       .WillOnce(CloseBrowserMock(&ie_mock_));
    132 
    133   LaunchIENavigateAndLoop(page1, kChromeFrameVeryLongNavigationTimeout);
    134 }
    135 
    136 // Tests new window behavior with ctrl+N.
    137 TEST_P(FullTabUITest, CtrlN) {
    138   if (IsWorkstationLocked()) {
    139     LOG(ERROR) << "This test cannot be run in a locked workstation.";
    140     return;
    141   }
    142 
    143   bool is_cf = GetParam().invokes_cf();
    144   if (!is_cf) {
    145     LOG(ERROR) << "Test not implemented for this configuration.";
    146     return;
    147   }
    148   // Ideally we want to use a ie_mock_ to watch for finer grained
    149   // events for New Window, but for Crl+N we don't get any
    150   // OnNewWindowX notifications. :(
    151   MockWindowObserver win_observer_mock;
    152 
    153   const char* kNewWindowTitlePattern = "*Internet Explorer*";
    154   EXPECT_CALL(ie_mock_, OnLoad(is_cf, StrEq(GetSimplePageUrl())))
    155       .WillOnce(testing::DoAll(
    156           WatchWindow(&win_observer_mock, kNewWindowTitlePattern, ""),
    157           SetFocusToRenderer(&ie_mock_),
    158           DelaySendChar(&loop_,
    159                         base::TimeDelta::FromSeconds(1),
    160                         'n',
    161                         simulate_input::CONTROL)));
    162 
    163   // Watch for new window. It appears that the window close message cannot be
    164   // reliably delivered immediately upon receipt of the window open event.
    165   EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    166       .Times(testing::AtMost(2))
    167       .WillOnce(CloseBrowserMock(&ie_mock_))
    168       .WillOnce(testing::Return());
    169 
    170   EXPECT_CALL(win_observer_mock, OnWindowClose(_))
    171       .Times(testing::AtMost(2));
    172 
    173   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    174                           kChromeFrameVeryLongNavigationTimeout);
    175 }
    176 
    177 // Test that Ctrl+F opens the Find dialog.
    178 TEST_P(FullTabUITest, CtrlF) {
    179   if (IsWorkstationLocked()) {
    180     LOG(ERROR) << "This test cannot be run in a locked workstation.";
    181     return;
    182   }
    183 
    184   bool is_cf = GetParam().invokes_cf();
    185   if (!is_cf) {
    186     LOG(ERROR) << "Test not implemented for this configuration.";
    187     return;
    188   }
    189   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    190   MockWindowObserver win_observer_mock;
    191   InSequence expect_in_sequence_for_scope;
    192 
    193   const char* kFindDialogCaption = "Find";
    194   EXPECT_CALL(ie_mock_, OnLoad(IN_CF, StrEq(GetSimplePageUrl())))
    195       .WillOnce(testing::DoAll(
    196           WatchWindow(&win_observer_mock, kFindDialogCaption, ""),
    197           SetFocusToRenderer(&ie_mock_),
    198           DelaySendChar(&loop_,
    199                         base::TimeDelta::FromMilliseconds(1500),
    200                         'f',
    201                         simulate_input::CONTROL)));
    202 
    203   EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    204       .WillOnce(CloseBrowserMock(&ie_mock_));
    205 
    206   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    207                           kChromeFrameVeryLongNavigationTimeout);
    208 }
    209 
    210 // Test that ctrl+r does cause a refresh.
    211 TEST_P(FullTabUITest, CtrlR) {
    212   if (IsWorkstationLocked()) {
    213     LOG(ERROR) << "This test cannot be run in a locked workstation.";
    214     return;
    215   }
    216 
    217   EXPECT_CALL(server_mock_, Get(_, UrlPathEq(GetSimplePageUrl()), _))
    218       .Times(testing::AtMost(2))
    219       .WillRepeatedly(SendResponse(&server_mock_, GetParam()));
    220 
    221   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(),
    222                                StrEq(GetSimplePageUrl())))
    223       .Times(testing::AtMost(2))
    224       .WillOnce(testing::DoAll(
    225           SetFocusToRenderer(&ie_mock_),
    226           DelaySendChar(&loop_,
    227                         base::TimeDelta::FromSeconds(1),
    228                         'r',
    229                         simulate_input::CONTROL),
    230           DelayCloseBrowserMock(
    231               &loop_, base::TimeDelta::FromSeconds(4), &ie_mock_)))
    232       .WillRepeatedly(testing::Return());
    233 
    234   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    235                           kChromeFrameVeryLongNavigationTimeout);
    236 }
    237 
    238 // Test window close with ctrl+w.
    239 TEST_P(FullTabUITest, CtrlW) {
    240   if (IsWorkstationLocked()) {
    241     LOG(ERROR) << "This test cannot be run in a locked workstation.";
    242     return;
    243   }
    244 
    245   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(),
    246                                StrEq(GetSimplePageUrl())))
    247       .WillOnce(testing::DoAll(
    248           SetFocusToRenderer(&ie_mock_),
    249           DelaySendChar(&loop_,
    250                         base::TimeDelta::FromSeconds(1),
    251                         'w',
    252                         simulate_input::CONTROL)));
    253 
    254   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    255                           kChromeFrameVeryLongNavigationTimeout);
    256 }
    257 
    258 // Test address bar navigation with Alt+d and URL.
    259 // Flaky due to TypeUrlInAddressBar; see http://crbug.com/124244.
    260 TEST_P(FullTabUITest, DISABLED_AltD) {
    261   if (IsWorkstationLocked()) {
    262     LOG(ERROR) << "This test cannot be run in a locked workstation.";
    263     return;
    264   }
    265 
    266   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(),
    267                                StrEq(GetSimplePageUrl())))
    268       .WillOnce(testing::DoAll(
    269           SetFocusToRenderer(&ie_mock_),
    270           TypeUrlInAddressBar(&loop_,
    271                               GetLinkPageUrl(),
    272                               base::TimeDelta::FromMilliseconds(1500))));
    273 
    274   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(),
    275                                StrEq(GetLinkPageUrl())))
    276       .WillOnce(CloseBrowserMock(&ie_mock_));
    277 
    278   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    279                           kChromeFrameVeryLongNavigationTimeout);
    280 }
    281 
    282 // Tests that the renderer has focus after navigation.
    283 // Flaky, see http://crbug.com/90791 .
    284 TEST_P(FullTabUITest, DISABLED_RendererHasFocus) {
    285   EXPECT_CALL(ie_mock_, OnLoad(GetParam().invokes_cf(),
    286                                StrEq(GetSimplePageUrl())))
    287       .WillOnce(testing::DoAll(
    288           ExpectRendererHasFocus(&ie_mock_),
    289           CloseBrowserMock(&ie_mock_)));
    290 
    291   LaunchIEAndNavigate(GetSimplePageUrl());
    292 }
    293 
    294 // Tests that view source works.
    295 TEST_P(FullTabUITest, ViewSource) {
    296   // Please see http://code.google.com/p/chromium/issues/detail?id=60987
    297   // for more information on why this test is disabled for Vista with IE7.
    298   if (base::win::GetVersion() == base::win::VERSION_VISTA &&
    299       GetInstalledIEVersion() == IE_7) {
    300     LOG(INFO) << "Not running test on Vista with IE7";
    301     return;
    302   }
    303 
    304   bool in_cf = GetParam().invokes_cf();
    305   if (!in_cf) {
    306     LOG(ERROR) << "Test not implemented for this configuration.";
    307     return;
    308   }
    309   MockIEEventSink view_source_mock;
    310   view_source_mock.ExpectAnyNavigations();
    311   InSequence expect_in_sequence_for_scope;
    312 
    313   // After navigation invoke view soruce action using IWebBrowser2::ExecWB
    314   VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
    315   EXPECT_CALL(ie_mock_, OnLoad(in_cf,
    316                                StrEq(GetSimplePageUrl())))
    317       .WillOnce(DelayExecCommand(
    318           &ie_mock_, &loop_, base::TimeDelta(), &CGID_MSHTML,
    319           static_cast<OLECMDID>(IDM_VIEWSOURCE),
    320           OLECMDEXECOPT_DONTPROMPTUSER, &empty, &empty));
    321 
    322   // Expect notification for view-source window, handle new window event
    323   // and attach a new ie_mock_ to the received web browser
    324   std::wstring view_source_url;
    325   view_source_url += UTF8ToWide(content::kViewSourceScheme);
    326   view_source_url += L":";
    327   view_source_url += GetSimplePageUrl();
    328   std::wstring url_in_new_window = kChromeProtocolPrefix;
    329   url_in_new_window += view_source_url;
    330 
    331   ie_mock_.ExpectNewWindow(&view_source_mock);
    332   // For some reason this happens occasionally at least on XP IE7.
    333   EXPECT_CALL(view_source_mock, OnLoad(IN_IE, StrEq(url_in_new_window)))
    334       .Times(testing::AtMost(1));
    335   EXPECT_CALL(view_source_mock, OnLoad(in_cf, StrEq(view_source_url)))
    336       .WillOnce(testing::DoAll(
    337           VerifyAddressBarUrlWithGcf(&view_source_mock),
    338           CloseBrowserMock(&view_source_mock)));
    339 
    340   EXPECT_CALL(view_source_mock, OnQuit())
    341       .Times(testing::AtMost(1))
    342       .WillOnce(CloseBrowserMock(&ie_mock_));
    343 
    344   LaunchIEAndNavigate(GetSimplePageUrl());
    345 }
    346 
    347 void NavigateToCurrentUrl(MockIEEventSink* mock) {
    348   IWebBrowser2* browser = mock->event_sink()->web_browser2();
    349   DCHECK(browser);
    350   base::win::ScopedBstr bstr;
    351   HRESULT hr = browser->get_LocationURL(bstr.Receive());
    352   EXPECT_HRESULT_SUCCEEDED(hr);
    353   if (SUCCEEDED(hr)) {
    354     DCHECK(bstr.Length());
    355     VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
    356     hr = browser->Navigate(bstr, &empty, &empty, &empty, &empty);
    357     EXPECT_HRESULT_SUCCEEDED(hr);
    358   }
    359 }
    360 
    361 // Tests that Chrome gets re-instantiated after crash if we reload via
    362 // the address bar or via a new navigation.
    363 TEST_P(FullTabUITest, TabCrashReload) {
    364   using testing::DoAll;
    365 
    366   if (!GetParam().invokes_cf()) {
    367     LOG(ERROR) << "Test needs CF.";
    368     return;
    369   }
    370 
    371   MockPropertyNotifySinkListener prop_listener;
    372   InSequence expect_in_sequence_for_scope;
    373 
    374   EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl())))
    375       .WillOnce(DoAll(
    376           ExpectRendererHasFocus(&ie_mock_),
    377           ExpectDocumentReadystate(&ie_mock_, READYSTATE_COMPLETE),
    378           ConnectDocPropNotifySink(&ie_mock_, &prop_listener),
    379           KillChromeFrameProcesses()));
    380 
    381   EXPECT_CALL(prop_listener, OnChanged(DISPID_READYSTATE))
    382       .WillOnce(DoAll(
    383           ExpectDocumentReadystate(&ie_mock_, READYSTATE_UNINITIALIZED),
    384           DelayNavigateToCurrentUrl(
    385               &ie_mock_, &loop_, base::TimeDelta::FromMilliseconds(10))));
    386 
    387   EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl())))
    388       .WillOnce(CloseBrowserMock(&ie_mock_));
    389 
    390   LaunchIEAndNavigate(GetSimplePageUrl());
    391 }
    392 
    393 // Tests if Chrome gets restarted after a crash by just refreshing the document.
    394 // DISABLED as per bug http://crbug.com/99317 (one of the failures is a
    395 // timeout, which marking as FLAKY or FAILS won't mask).
    396 TEST_P(FullTabUITest, DISABLED_TabCrashRefresh) {
    397   using testing::DoAll;
    398 
    399   if (!GetParam().invokes_cf()) {
    400     LOG(ERROR) << "Test needs CF.";
    401     return;
    402   }
    403 
    404   MockPropertyNotifySinkListener prop_listener;
    405   InSequence expect_in_sequence_for_scope;
    406 
    407   EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl())))
    408       .WillOnce(DoAll(
    409           ExpectRendererHasFocus(&ie_mock_),
    410           ExpectDocumentReadystate(&ie_mock_, READYSTATE_COMPLETE),
    411           ConnectDocPropNotifySink(&ie_mock_, &prop_listener),
    412           KillChromeFrameProcesses()));
    413 
    414   VARIANT empty = base::win::ScopedVariant::kEmptyVariant;
    415   EXPECT_CALL(prop_listener, OnChanged(/*DISPID_READYSTATE*/_))
    416       .WillOnce(DoAll(
    417           DisconnectDocPropNotifySink(&prop_listener),
    418           ExpectDocumentReadystate(&ie_mock_, READYSTATE_UNINITIALIZED),
    419           DelayExecCommand(
    420               &ie_mock_, &loop_, base::TimeDelta::FromMilliseconds(10),
    421               static_cast<GUID*>(NULL), OLECMDID_REFRESH, 0, &empty, &empty)));
    422 
    423   EXPECT_CALL(ie_mock_, OnLoad(_, StrEq(GetSimplePageUrl())))
    424       .WillOnce(CloseBrowserMock(&ie_mock_));
    425 
    426   LaunchIEAndNavigate(GetSimplePageUrl());
    427 }
    428 
    429 // Test that window.print() on a page results in the native Windows print dialog
    430 // appearing rather than Chrome's in-page print preview.
    431 TEST_P(FullTabUITest, WindowPrintOpensNativePrintDialog) {
    432   std::wstring window_print_url(GetTestUrl(L"window_print.html"));
    433   std::wstring window_print_title(L"window.print");
    434 
    435   const bool is_cf = GetParam().invokes_cf();
    436   MockWindowObserver win_observer_mock;
    437 
    438   // When the page is loaded, start watching for the Print dialog to appear.
    439   EXPECT_CALL(ie_mock_, OnLoad(is_cf, StrEq(window_print_url)))
    440       .WillOnce(WatchWindow(&win_observer_mock, "Print", ""));
    441 
    442   // When the print dialog opens, close it.
    443   EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    444       .WillOnce(DoCloseWindow());
    445 
    446   // When the print dialog closes, close the browser.
    447   EXPECT_CALL(win_observer_mock, OnWindowClose(_))
    448       .WillOnce(CloseBrowserMock(&ie_mock_));
    449 
    450   // Launch IE and navigate to the window_print.html page, which will
    451   // window.print() immediately after loading.
    452   LaunchIEAndNavigate(window_print_url);
    453 }
    454 
    455 // Test fixture for tests related to the context menu UI. Since the context
    456 // menus for CF and IE are different, these tests are not parameterized.
    457 class ContextMenuTest : public MockIEEventSinkTest, public testing::Test {
    458  public:
    459   ContextMenuTest(): kTextFieldInitValue(L"SomeInitializedTextValue") {}
    460 
    461   virtual void SetUp() {
    462     context_menu_page_url = GetTestUrl(L"context_menu.html");
    463     context_menu_page_title = L"context menu";
    464     // Clear clipboard to make sure there is no effect from previous tests.
    465     SetClipboardText(L"");
    466     // These are UI-related tests, so we do not care about the exact
    467     // navigations that occur.
    468     ie_mock_.ExpectAnyNavigations();
    469     EXPECT_CALL(ie_mock_, OnLoad(_, _)).Times(testing::AnyNumber());
    470     EXPECT_CALL(acc_observer_, OnAccDocLoad(_)).Times(testing::AnyNumber());
    471   }
    472 
    473   virtual void TearDown() {
    474     // Destroy the clipboard here because it is not destroyed automatically.
    475     DestroyClipboard();
    476   }
    477 
    478   // Common helper function for "Save xxx As" tests.
    479   void DoSaveAsTest(const wchar_t* role, const wchar_t* menu_item_name,
    480                     const wchar_t* file_ext) {
    481     server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    482     MockWindowObserver win_observer_mock;
    483     InSequence expect_in_sequence_for_scope;
    484 
    485     // Open 'Save As' dialog.
    486     const char* kSaveDlgCaption = "Save As";
    487     EXPECT_CALL(acc_observer_,
    488                 OnAccDocLoad(TabContentsTitleEq(L"Save As download test")))
    489         .WillOnce(testing::DoAll(
    490             WatchWindow(&win_observer_mock, kSaveDlgCaption, ""),
    491             AccRightClick(AccObjectMatcher(L"", role))));
    492     EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    493         .WillOnce(AccLeftClick(AccObjectMatcher(menu_item_name)));
    494 
    495     // Get safe download name using temporary file.
    496     base::FilePath temp_file_path;
    497     ASSERT_TRUE(file_util::CreateTemporaryFile(&temp_file_path));
    498     ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false));
    499     temp_file_path = temp_file_path.ReplaceExtension(file_ext);
    500 
    501     AccObjectMatcher file_name_box(L"File name:", L"editable text");
    502     EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    503         .WillOnce(testing::DoAll(
    504             AccSendCharMessage(file_name_box, L'a'),
    505             AccSetValue(file_name_box, temp_file_path.value()),
    506             AccDoDefaultAction(AccObjectMatcher(L"Save", L"push button"))));
    507 
    508     EXPECT_CALL(win_observer_mock, OnWindowClose(_))
    509         .WillOnce(CloseWhenFileSaved(&ie_mock_, temp_file_path, 8000));
    510 
    511     LaunchIENavigateAndLoop(GetTestUrl(L"save_as_context_menu.html"),
    512                             kChromeFrameVeryLongNavigationTimeout);
    513     ASSERT_TRUE(file_util::DieFileDie(temp_file_path, false));
    514   }
    515 
    516  protected:
    517   // Html page that holds a text field for context menu testing.
    518   std::wstring context_menu_page_url;
    519   // Title of said html page.
    520   std::wstring context_menu_page_title;
    521   // This is the text value used to test cut/copy/paste etc.
    522   const std::wstring kTextFieldInitValue;
    523 
    524   testing::NiceMock<MockAccEventObserver> acc_observer_;
    525 };
    526 
    527 // Test reloading from the context menu.
    528 TEST_F(ContextMenuTest, CFReload) {
    529   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    530   InSequence expect_in_sequence_for_scope;
    531 
    532   EXPECT_CALL(acc_observer_,
    533               OnAccDocLoad(TabContentsTitleEq(GetSimplePageTitle())))
    534       .WillOnce(OpenContextMenuAsync());
    535   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    536       .WillOnce(AccLeftClick(AccObjectMatcher(L"Reload")));
    537 
    538   EXPECT_CALL(ie_mock_, OnLoad(IN_CF, StrEq(GetSimplePageUrl())))
    539       .WillOnce(CloseBrowserMock(&ie_mock_));
    540 
    541   LaunchIEAndNavigate(GetSimplePageUrl());
    542 }
    543 
    544 // Test view source from the context menu.
    545 TEST_F(ContextMenuTest, CFViewSource) {
    546   // Please see http://code.google.com/p/chromium/issues/detail?id=60987
    547   // for more information on why this test is disabled for Vista with IE7.
    548   if (base::win::GetVersion() == base::win::VERSION_VISTA &&
    549       GetInstalledIEVersion() == IE_7) {
    550     LOG(INFO) << "Not running test on Vista with IE7";
    551     return;
    552   }
    553   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    554   MockIEEventSink view_source_mock;
    555   view_source_mock.ExpectAnyNavigations();
    556   InSequence expect_in_sequence_for_scope;
    557 
    558   // View the page source.
    559   EXPECT_CALL(acc_observer_,
    560               OnAccDocLoad(TabContentsTitleEq(GetSimplePageTitle())))
    561       .WillOnce(OpenContextMenuAsync());
    562   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    563       .WillOnce(AccLeftClick(AccObjectMatcher(L"View page source")));
    564 
    565   // Expect notification for view-source window, handle new window event
    566   // and attach a new ie_mock_ to the received web browser
    567   std::wstring view_source_url;
    568   view_source_url += UTF8ToWide(content::kViewSourceScheme);
    569   view_source_url += L":";
    570   view_source_url += GetSimplePageUrl();
    571   std::wstring url_in_new_window = kChromeProtocolPrefix;
    572   url_in_new_window += view_source_url;
    573 
    574   ie_mock_.ExpectNewWindow(&view_source_mock);
    575   // For some reason this happens occasionally at least on XP IE7 and Win7 IE8.
    576   EXPECT_CALL(view_source_mock, OnLoad(IN_IE, StrEq(url_in_new_window)))
    577       .Times(testing::AtMost(1));
    578   EXPECT_CALL(view_source_mock, OnLoad(IN_CF, StrEq(view_source_url)))
    579       .WillOnce(testing::DoAll(
    580           VerifyAddressBarUrlWithGcf(&view_source_mock),
    581           CloseBrowserMock(&view_source_mock)));
    582   EXPECT_CALL(view_source_mock, OnQuit())
    583       .Times(testing::AtMost(1))
    584       .WillOnce(CloseBrowserMock(&ie_mock_));
    585 
    586   LaunchIEAndNavigate(GetSimplePageUrl());
    587 }
    588 
    589 TEST_F(ContextMenuTest, DISABLED_CFPageInfo) {
    590   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    591   MockWindowObserver win_observer_mock;
    592   InSequence expect_in_sequence_for_scope;
    593 
    594   // View page information.
    595   EXPECT_CALL(acc_observer_,
    596               OnAccDocLoad(TabContentsTitleEq(GetSimplePageTitle())))
    597       .WillOnce(testing::DoAll(
    598           WatchWindow(&win_observer_mock, "", "Chrome_WidgetWin_*"),
    599           OpenContextMenuAsync()));
    600   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    601       .WillOnce(AccLeftClick(AccObjectMatcher(L"View page info")));
    602 
    603   EXPECT_CALL(win_observer_mock, OnWindowOpen(_)).Times(1);
    604   // Expect page info dialog to pop up. Dismiss the dialog with 'Esc' key
    605   EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    606       .WillOnce(DoCloseWindow());
    607 
    608   EXPECT_CALL(win_observer_mock, OnWindowClose(_)).Times(1);
    609   EXPECT_CALL(win_observer_mock, OnWindowClose(_))
    610     .WillOnce(CloseBrowserMock(&ie_mock_));
    611 
    612   LaunchIEAndNavigate(GetSimplePageUrl());
    613 }
    614 
    615 TEST_F(ContextMenuTest, CFInspector) {
    616   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    617   MockWindowObserver win_observer_mock;
    618   InSequence expect_in_sequence_for_scope;
    619 
    620   // Open developer tools.
    621   // Devtools begins life with "Untitled" caption and it changes
    622   // later to the 'Developer Tools - <url> form.
    623   const char* kPageInfoCaptionPattern = "Untitled*";
    624   EXPECT_CALL(acc_observer_,
    625               OnAccDocLoad(TabContentsTitleEq(GetSimplePageTitle())))
    626       .WillOnce(testing::DoAll(
    627           WatchWindow(&win_observer_mock, kPageInfoCaptionPattern, ""),
    628           OpenContextMenuAsync()));
    629   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    630       .WillOnce(AccLeftClick(AccObjectMatcher(L"Inspect element")));
    631 
    632   EXPECT_CALL(win_observer_mock, OnWindowOpen(_))
    633       .WillOnce(DelayDoCloseWindow(5000));  // wait to catch possible crash
    634   EXPECT_CALL(win_observer_mock, OnWindowClose(_))
    635       .WillOnce(CloseBrowserMock(&ie_mock_));
    636 
    637   LaunchIENavigateAndLoop(GetSimplePageUrl(),
    638                           kChromeFrameVeryLongNavigationTimeout);
    639 }
    640 
    641 // http://code.google.com/p/chromium/issues/detail?id=83114
    642 TEST_F(ContextMenuTest, DISABLED_CFSavePageAs) {
    643   // Please see http://code.google.com/p/chromium/issues/detail?id=60987
    644   // for more information on why this test is disabled for Vista with IE7.
    645   if (base::win::GetVersion() == base::win::VERSION_VISTA &&
    646       GetInstalledIEVersion() == IE_7) {
    647     LOG(INFO) << "Not running test on Vista with IE7";
    648     return;
    649   }
    650   ASSERT_NO_FATAL_FAILURE(DoSaveAsTest(L"", L"Save as...", L".html"));
    651 }
    652 
    653 // http://code.google.com/p/chromium/issues/detail?id=83114
    654 TEST_F(ContextMenuTest, DISABLED_CFSaveLinkAs) {
    655   // Please see http://code.google.com/p/chromium/issues/detail?id=60987
    656   // for more information on why this test is disabled for Vista with IE7.
    657   if (base::win::GetVersion() == base::win::VERSION_VISTA &&
    658       GetInstalledIEVersion() == IE_7) {
    659     LOG(INFO) << "Not running test on Vista with IE7";
    660     return;
    661   }
    662   ASSERT_NO_FATAL_FAILURE(DoSaveAsTest(L"link", L"Save link as...", L".zip"));
    663 }
    664 
    665 // This tests that the about:version page can be opened via the CF context menu.
    666 TEST_F(ContextMenuTest, CFAboutVersionLoads) {
    667   // Please see http://code.google.com/p/chromium/issues/detail?id=60987
    668   // for more information on why this test is disabled for Vista with IE7.
    669   if (base::win::GetVersion() == base::win::VERSION_VISTA &&
    670       GetInstalledIEVersion() == IE_7) {
    671     LOG(INFO) << "Not running test on Vista with IE7";
    672     return;
    673   }
    674   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    675   const wchar_t* kAboutVersionUrl = L"gcf:about:version";
    676   const wchar_t* kAboutVersionWithoutProtoUrl = L"about:version";
    677   MockIEEventSink new_window_mock;
    678   new_window_mock.ExpectAnyNavigations();
    679   InSequence expect_in_sequence_for_scope;
    680 
    681   EXPECT_CALL(acc_observer_,
    682               OnAccDocLoad(TabContentsTitleEq(GetSimplePageTitle())))
    683       .WillOnce(OpenContextMenuAsync());
    684   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    685       .WillOnce(AccLeftClick(AccObjectMatcher(L"About*")));
    686 
    687   ie_mock_.ExpectNewWindow(&new_window_mock);
    688   // For some reason this happens occasionally at least on Win7 IE8.
    689   EXPECT_CALL(new_window_mock, OnLoad(IN_IE, StrEq(kAboutVersionUrl)))
    690       .Times(testing::AtMost(1));
    691   EXPECT_CALL(new_window_mock,
    692               OnLoad(IN_CF, StrEq(kAboutVersionWithoutProtoUrl)))
    693       .WillOnce(testing::DoAll(
    694           VerifyAddressBarUrlWithGcf(&new_window_mock),
    695           CloseBrowserMock(&new_window_mock)));
    696 
    697   EXPECT_CALL(new_window_mock, OnQuit())
    698       .Times(testing::AtMost(1))
    699       .WillOnce(CloseBrowserMock(&ie_mock_));
    700 
    701   LaunchIEAndNavigate(GetSimplePageUrl());
    702 }
    703 
    704 TEST_F(ContextMenuTest, IEOpen) {
    705   server_mock_.ExpectAndServeAnyRequests(CFInvocation::None());
    706   InSequence expect_in_sequence_for_scope;
    707 
    708   // Open the link through the context menu.
    709   EXPECT_CALL(acc_observer_,
    710               OnAccDocLoad(TabContentsTitleEq(GetLinkPageTitle())))
    711       .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link")));
    712   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    713       .WillOnce(AccLeftClick(AccObjectMatcher(L"Open")));
    714 
    715   EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(GetSimplePageUrl())))
    716       .WillOnce(testing::DoAll(
    717           VerifyAddressBarUrl(&ie_mock_),
    718           CloseBrowserMock(&ie_mock_)));
    719 
    720   LaunchIEAndNavigate(GetLinkPageUrl());
    721 }
    722 
    723 TEST_F(ContextMenuTest, IEOpenInNewWindow) {
    724   // See crbug.com/64794.
    725   if (GetInstalledIEVersion() == IE_7) {
    726     LOG(INFO) << "Not running test with IE7";
    727     return;
    728   }
    729   server_mock_.ExpectAndServeAnyRequests(CFInvocation::None());
    730   MockIEEventSink new_window_mock;
    731   new_window_mock.ExpectAnyNavigations();
    732   InSequence expect_in_sequence_for_scope;
    733 
    734   // Open the link in a new window.
    735   EXPECT_CALL(acc_observer_,
    736               OnAccDocLoad(TabContentsTitleEq(GetLinkPageTitle())))
    737       .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link")));
    738   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    739       .WillOnce(AccLeftClick(AccObjectMatcher(L"Open in New Window")));
    740 
    741   ie_mock_.ExpectNewWindow(&new_window_mock);
    742   EXPECT_CALL(new_window_mock, OnLoad(IN_IE, StrEq(GetSimplePageUrl())))
    743       // TODO(kkania): Verifying the address bar is flaky with this, at least
    744       // on XP ie6. Fix.
    745       .WillOnce(CloseBrowserMock(&new_window_mock));
    746 
    747   EXPECT_CALL(new_window_mock, OnQuit())
    748       .Times(testing::AtMost(1))
    749       .WillOnce(CloseBrowserMock(&ie_mock_));
    750 
    751   LaunchIEAndNavigate(GetLinkPageUrl());
    752 }
    753 
    754 // Test Back/Forward from context menu.
    755 TEST_F(ContextMenuTest, IEBackForward) {
    756   server_mock_.ExpectAndServeAnyRequests(CFInvocation::None());
    757   std::wstring page1 = GetLinkPageUrl();
    758   std::wstring title1 = GetLinkPageTitle();
    759   std::wstring page2 = GetSimplePageUrl();
    760   std::wstring title2 = GetSimplePageTitle();
    761   InSequence expect_in_sequence_for_scope;
    762 
    763   // Navigate to second page.
    764   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title1)))
    765       .WillOnce(Navigate(&ie_mock_, page2));
    766 
    767   // Go back.
    768   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title2)))
    769       .WillOnce(testing::DoAll(
    770           VerifyPageLoad(&ie_mock_, IN_IE, page2),
    771           OpenContextMenuAsync()));
    772   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    773       .WillOnce(AccLeftClick(AccObjectMatcher(L"Back")));
    774 
    775   // Go forward.
    776   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title1)))
    777       .WillOnce(testing::DoAll(
    778           VerifyPageLoad(&ie_mock_, IN_IE, page1),
    779           OpenContextMenuAsync()));
    780   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    781       .WillOnce(AccLeftClick(AccObjectMatcher(L"Forward")));
    782 
    783   EXPECT_CALL(ie_mock_, OnLoad(IN_IE, StrEq(page2)))
    784       .WillOnce(CloseBrowserMock(&ie_mock_));
    785 
    786   LaunchIEAndNavigate(page1);
    787 }
    788 
    789 // Test CF link context menu - Open link in new window.
    790 // Failing intermittently on IE6/7. See crbug.com/64794.
    791 TEST_F(ContextMenuTest, DISABLED_CFOpenLinkInNewWindow) {
    792   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    793   MockIEEventSink new_window_mock;
    794   new_window_mock.ExpectAnyNavigations();
    795 
    796   // Invoke 'Open link in new window' context menu item.
    797   EXPECT_CALL(acc_observer_,
    798               OnAccDocLoad(TabContentsTitleEq(GetLinkPageTitle())))
    799       .Times(testing::AtMost(2))
    800       .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link")))
    801       .WillOnce(testing::Return());
    802   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    803       .WillOnce(AccLeftClick(AccObjectMatcher(L"Open link in new window*")));
    804 
    805   ie_mock_.ExpectNewWindow(&new_window_mock);
    806   EXPECT_CALL(new_window_mock, OnLoad(IN_CF, StrEq(GetSimplePageUrl())))
    807       .WillOnce(CloseBrowserMock(&new_window_mock));
    808   EXPECT_CALL(new_window_mock, OnQuit())
    809       .WillOnce(CloseBrowserMock(&ie_mock_));
    810 
    811   LaunchIEAndNavigate(GetLinkPageUrl());
    812 }
    813 
    814 // Test CF link context menu - Copy link address.
    815 TEST_F(ContextMenuTest, CFCopyLinkAddress) {
    816   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    817 
    818   // Invoke 'Copy link address' context menu item.
    819   EXPECT_CALL(acc_observer_,
    820               OnAccDocLoad(TabContentsTitleEq(GetLinkPageTitle())))
    821       .WillOnce(AccRightClick(AccObjectMatcher(L"", L"link")));
    822   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    823       .WillOnce(testing::DoAll(
    824           AccLeftClick(AccObjectMatcher(L"Copy link address*")),
    825           CloseBrowserMock(&ie_mock_)));
    826 
    827   LaunchIEAndNavigate(GetLinkPageUrl());
    828 
    829   EXPECT_STREQ(GetSimplePageUrl().c_str(), GetClipboardText().c_str());
    830 }
    831 
    832 // Test CF text field context menu - cut.
    833 // Times out sporadically http://crbug.com/119660.
    834 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldCut) {
    835   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    836   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    837 
    838   // Invoke "Cut" context menu item of text field.
    839   EXPECT_CALL(acc_observer_,
    840               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    841       .WillOnce(testing::DoAll(
    842           AccRightClick(txtfield_matcher),
    843           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher)));
    844   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    845     .WillOnce(AccLeftClick(AccObjectMatcher(L"Cut*")));
    846 
    847   // Verify that text field is empty after cut operation.
    848   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"")))
    849       .WillOnce(CloseBrowserMock(&ie_mock_));
    850 
    851   LaunchIEAndNavigate(context_menu_page_url);
    852   // Verify that the text value has been cut to clipboard.
    853   EXPECT_STREQ(kTextFieldInitValue.c_str(), GetClipboardText().c_str());
    854 }
    855 
    856 // Test CF text field context menu - copy.
    857 // Times out sporadically http://crbug.com/119660.
    858 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldCopy) {
    859   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    860   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    861 
    862   // Invoke "Copy" context menu item of text field.
    863   EXPECT_CALL(acc_observer_,
    864               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    865       .WillOnce(testing::DoAll(
    866           AccRightClick(txtfield_matcher),
    867           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher)));
    868   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    869     .WillOnce(testing::DoAll(
    870         AccLeftClick(AccObjectMatcher(L"Copy*")),
    871         CloseBrowserMock(&ie_mock_)));
    872 
    873   // Verify that there is no change on text field value after copy operation.
    874   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, _))
    875       .Times(testing::AtMost(0));
    876 
    877   LaunchIEAndNavigate(context_menu_page_url);
    878   // Verify that the text value has been copied to clipboard.
    879   EXPECT_STREQ(kTextFieldInitValue.c_str(), GetClipboardText().c_str());
    880 }
    881 
    882 // Test CF text field context menu - paste.
    883 // Times out sporadically http://crbug.com/119660.
    884 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldPaste) {
    885   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    886   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    887 
    888   // Invoke "Paste" context menu item of text field.
    889   EXPECT_CALL(acc_observer_,
    890               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    891       .WillOnce(testing::DoAll(
    892           AccRightClick(txtfield_matcher),
    893           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher)));
    894   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    895       .WillOnce(AccLeftClick(AccObjectMatcher(L"Paste*")));
    896   // Verify that value has been pasted to text field.
    897   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue)))
    898       .WillOnce(CloseBrowserMock(&ie_mock_));
    899 
    900   // Set some text value to clipboard, this is to emulate the 'copy' action.
    901   SetClipboardText(kTextFieldInitValue);
    902 
    903   LaunchIEAndNavigate(context_menu_page_url);
    904 }
    905 
    906 // Test CF text field context menu - delete.
    907 // Times out sporadically http://crbug.com/119660.
    908 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldDelete) {
    909   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    910   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    911 
    912   // Invoke 'Delete' context menu item of text field.
    913   EXPECT_CALL(acc_observer_,
    914               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    915       .WillOnce(testing::DoAll(
    916           AccRightClick(txtfield_matcher),
    917           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher)));
    918   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    919       .WillOnce(AccLeftClick(AccObjectMatcher(L"Delete*")));
    920   // Verify that value has been deleted from text field.
    921   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"")))
    922       .WillOnce(CloseBrowserMock(&ie_mock_));
    923 
    924   LaunchIEAndNavigate(context_menu_page_url);
    925 }
    926 
    927 // Test CF text field context menu - select all.
    928 // Flaky: http://crbug.com/144664
    929 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldSelectAll) {
    930   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    931 
    932   // Invoke 'Select all' context menu item of text field.
    933   EXPECT_CALL(acc_observer_,
    934               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    935       .WillOnce(AccRightClick(AccObjectMatcher(L"", L"editable text")));
    936   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    937       .WillOnce(testing::DoAll(
    938           AccLeftClick(AccObjectMatcher(L"Select all*")),
    939           PostMessageToCF(&ie_mock_, L"selectall")));
    940   // Client side script verifies that the text field value has been selected,
    941   // then send 'OK' message.
    942   EXPECT_CALL(ie_mock_, OnMessage(testing::StrCaseEq(L"OK"), _, _))
    943       .WillOnce(CloseBrowserMock(&ie_mock_));
    944 
    945   LaunchIEAndNavigate(context_menu_page_url + L"?action=selectall");
    946 }
    947 
    948 // Test CF text field context menu - undo.
    949 // Times out sporadically http://crbug.com/119660.
    950 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldUndo) {
    951   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    952   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    953 
    954   // Change the value of text field to 'A'.
    955   EXPECT_CALL(acc_observer_,
    956               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    957       .WillOnce(testing::DoAll(
    958           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher),
    959           AccSendCharMessage(txtfield_matcher, L'A')));
    960   // Bring up the context menu once the value has changed.
    961   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"A")))
    962       .WillOnce(AccRightClick(txtfield_matcher));
    963   // Then select "Undo".
    964   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    965       .WillOnce(testing::DoAll(
    966           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher),
    967           AccLeftClick(AccObjectMatcher(L"Undo*"))));
    968 
    969   // Verify that value has been reset to initial value after undo operation.
    970   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue)))
    971       .WillOnce(CloseBrowserMock(&ie_mock_));
    972 
    973   LaunchIEAndNavigate(context_menu_page_url);
    974 }
    975 
    976 // Test CF text field context menu - redo.
    977 // Times out sporadically http://crbug.com/119660.
    978 TEST_F(ContextMenuTest, DISABLED_CFTxtFieldRedo) {
    979   server_mock_.ExpectAndServeAnyRequests(CFInvocation::MetaTag());
    980   AccObjectMatcher txtfield_matcher(L"", L"editable text");
    981   InSequence expect_in_sequence_for_scope;
    982 
    983   // Change text field from its initial value to 'A'.
    984   EXPECT_CALL(acc_observer_,
    985               OnAccDocLoad(TabContentsTitleEq(context_menu_page_title)))
    986       .WillOnce(testing::DoAll(
    987           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher),
    988           AccSendCharMessage(txtfield_matcher, L'A')));
    989   // Bring up the context menu.
    990   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"A")))
    991       .WillOnce(AccRightClick(txtfield_matcher));
    992   // Select "Undo"
    993   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
    994       .WillOnce(testing::DoAll(
    995           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher),
    996           AccLeftClick(AccObjectMatcher(L"Undo*"))));
    997 
    998   // After undo operation is done, bring up the context menu again.
    999   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(kTextFieldInitValue)))
   1000       .WillOnce(AccRightClick(txtfield_matcher));
   1001   // Select "Redo"
   1002   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
   1003       .WillOnce(testing::DoAll(
   1004           AccWatchForOneValueChange(&acc_observer_, txtfield_matcher),
   1005           AccLeftClick(AccObjectMatcher(L"Redo*"))));
   1006 
   1007   // Verify that text field value is reset to its changed value 'A' and exit.
   1008   EXPECT_CALL(acc_observer_, OnAccValueChange(_, _, StrEq(L"A")))
   1009       .WillOnce(CloseBrowserMock(&ie_mock_));
   1010 
   1011   LaunchIEAndNavigate(context_menu_page_url);
   1012 }
   1013 
   1014 // Disabled because it seems to hang, causing the test process to timeout and
   1015 // be killed; see http://crbug.com/121097.
   1016 TEST_F(ContextMenuTest, DISABLED_CFBackForward) {
   1017   std::wstring page1 = GetLinkPageUrl();
   1018   std::wstring title1 = GetLinkPageTitle();
   1019   std::wstring page2 = GetSimplePageUrl();
   1020   std::wstring title2 = GetSimplePageTitle();
   1021   std::wstring page3 = GetTestUrl(L"anchor.html");
   1022   std::wstring title3 = GetAnchorPageTitle();
   1023 
   1024   server_mock_.ExpectAndServeRequestWithCardinality(
   1025       CFInvocation::MetaTag(), page1, testing::Exactly(2));
   1026 
   1027   server_mock_.ExpectAndServeRequestWithCardinality(
   1028       CFInvocation::None(), page2, testing::Exactly(3));
   1029 
   1030   server_mock_.ExpectAndServeRequestWithCardinality(
   1031       CFInvocation::MetaTag(), page3, testing::Exactly(2));
   1032 
   1033   InSequence expect_in_sequence_for_scope;
   1034 
   1035   // Navigate to second page.
   1036   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title1)))
   1037       .WillOnce(testing::DoAll(
   1038           VerifyPageLoad(&ie_mock_, IN_CF, page1),
   1039           Navigate(&ie_mock_, page2)));
   1040 
   1041   // Navigate to third page.
   1042   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title2)))
   1043       .WillOnce(testing::DoAll(
   1044           VerifyPageLoad(&ie_mock_, IN_IE, page2),
   1045           Navigate(&ie_mock_, page3)));
   1046 
   1047   // Go back.
   1048   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title3)))
   1049       .WillOnce(testing::DoAll(
   1050           VerifyPageLoad(&ie_mock_, IN_CF, page3),
   1051           OpenContextMenuAsync()));
   1052 
   1053   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
   1054       .WillOnce(AccLeftClick(AccObjectMatcher(L"Back")));
   1055 
   1056   // Go back
   1057   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title2)))
   1058       .WillOnce(testing::DoAll(
   1059           VerifyPageLoad(&ie_mock_, IN_IE, page2),
   1060           OpenContextMenuAsync()));
   1061 
   1062   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
   1063       .WillOnce(AccLeftClick(AccObjectMatcher(L"Back")));
   1064 
   1065   // Go forward.
   1066   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title1)))
   1067       .WillOnce(testing::DoAll(
   1068           VerifyPageLoad(&ie_mock_, IN_CF, page1),
   1069           OpenContextMenuAsync()));
   1070 
   1071   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
   1072       .WillOnce(AccLeftClick(AccObjectMatcher(L"Forward")));
   1073 
   1074   // Go forward.
   1075   EXPECT_CALL(acc_observer_, OnAccDocLoad(TabContentsTitleEq(title2)))
   1076       .WillOnce(testing::DoAll(
   1077           VerifyPageLoad(&ie_mock_, IN_IE, page2),
   1078           OpenContextMenuAsync()));
   1079 
   1080   EXPECT_CALL(acc_observer_, OnMenuPopup(_))
   1081       .WillOnce(AccLeftClick(AccObjectMatcher(L"Forward")));
   1082 
   1083   EXPECT_CALL(ie_mock_, OnLoad(IN_CF, StrEq(page3)))
   1084       .WillOnce(CloseBrowserMock(&ie_mock_));
   1085 
   1086   LaunchIENavigateAndLoop(page1, kChromeFrameVeryLongNavigationTimeout);
   1087 }
   1088 
   1089 }  // namespace chrome_frame_test
   1090