root/content/browser/accessibility/accessibility_mode_browsertest.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. web_contents
  2. rwhi
  3. host_view
  4. ExpectBrowserAccessibilityManager
  5. IN_PROC_BROWSER_TEST_F
  6. IN_PROC_BROWSER_TEST_F
  7. IN_PROC_BROWSER_TEST_F
  8. IN_PROC_BROWSER_TEST_F

// Copyright 2014 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 "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/port/browser/render_widget_host_view_port.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/test/accessibility_browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

const char kMinimalPageDataURL[] =
    "data:text/html,<html><head></head><body>Hello, world</body></html>";

class AccessibilityModeTest : public ContentBrowserTest {
 protected:
  content::WebContents* web_contents() {
    return shell()->web_contents();
  }

  content::RenderWidgetHostImpl* rwhi() {
    content::RenderWidgetHost* rwh =
        web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost();
    return content::RenderWidgetHostImpl::From(rwh);
  }

  content::RenderWidgetHostViewPort* host_view() {
    return RenderWidgetHostViewPort::FromRWHV(
        shell()->web_contents()->GetRenderWidgetHostView());
  }

  void ExpectBrowserAccessibilityManager(bool expect_bam,
                                         std::string message = "") {
    if (expect_bam) {
      EXPECT_NE((BrowserAccessibilityManager*)NULL,
                host_view()->GetBrowserAccessibilityManager()) << message;
    } else {
      EXPECT_EQ((BrowserAccessibilityManager*)NULL,
                host_view()->GetBrowserAccessibilityManager()) << message;
    }
  }
};

IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeOff) {
  NavigateToURL(shell(), GURL(kMinimalPageDataURL));

  EXPECT_EQ(AccessibilityModeOff, rwhi()->accessibility_mode());
  ExpectBrowserAccessibilityManager(false);
}

IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeComplete) {
  NavigateToURL(shell(), GURL(kMinimalPageDataURL));
  ASSERT_EQ(AccessibilityModeOff, rwhi()->accessibility_mode());

  AccessibilityNotificationWaiter waiter(shell());
  rwhi()->AddAccessibilityMode(AccessibilityModeComplete);
  EXPECT_EQ(AccessibilityModeComplete, rwhi()->accessibility_mode());
  waiter.WaitForNotification();
  ExpectBrowserAccessibilityManager(true);
}

IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AccessibilityModeTreeOnly) {
  NavigateToURL(shell(), GURL(kMinimalPageDataURL));
  ASSERT_EQ(AccessibilityModeOff, rwhi()->accessibility_mode());

  AccessibilityNotificationWaiter waiter(shell());
  rwhi()->AddAccessibilityMode(AccessibilityModeTreeOnly);
  EXPECT_EQ(AccessibilityModeTreeOnly, rwhi()->accessibility_mode());
  waiter.WaitForNotification();
  // No BrowserAccessibilityManager expected for AccessibilityModeTreeOnly
  ExpectBrowserAccessibilityManager(false);
}

IN_PROC_BROWSER_TEST_F(AccessibilityModeTest, AddingModes) {
  NavigateToURL(shell(), GURL(kMinimalPageDataURL));

  AccessibilityNotificationWaiter waiter(shell());
  rwhi()->AddAccessibilityMode(AccessibilityModeTreeOnly);
  EXPECT_EQ(AccessibilityModeTreeOnly, rwhi()->accessibility_mode());
  waiter.WaitForNotification();
  ExpectBrowserAccessibilityManager(false,
                                    "Should be no BrowserAccessibilityManager "
                                    "for AccessibilityModeTreeOnly");

  AccessibilityNotificationWaiter waiter2(shell());
  rwhi()->AddAccessibilityMode(AccessibilityModeComplete);
  EXPECT_EQ(AccessibilityModeComplete, rwhi()->accessibility_mode());
  waiter2.WaitForNotification();
  ExpectBrowserAccessibilityManager(true,
                                    "Should be a BrowserAccessibilityManager "
                                    "for AccessibilityModeComplete");
}

}  // namespace content

/* [<][>][^][v][top][bottom][index][help] */