Home | History | Annotate | Download | only in test_runner
      1 // Copyright 2014 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 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
      6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "gin/object_template_builder.h"
     12 #include "gin/wrappable.h"
     13 #include "third_party/WebKit/public/web/WebAXObject.h"
     14 #include "v8/include/v8-util.h"
     15 #include "v8/include/v8.h"
     16 
     17 namespace blink {
     18 class WebFrame;
     19 }
     20 
     21 namespace content {
     22 
     23 class WebAXObjectProxy : public gin::Wrappable<WebAXObjectProxy> {
     24  public:
     25   class Factory {
     26    public:
     27     virtual ~Factory() { }
     28     virtual v8::Handle<v8::Object> GetOrCreate(
     29         const blink::WebAXObject& object) = 0;
     30   };
     31 
     32   static gin::WrapperInfo kWrapperInfo;
     33 
     34   WebAXObjectProxy(const blink::WebAXObject& object, Factory* factory);
     35   virtual ~WebAXObjectProxy();
     36 
     37   // gin::Wrappable:
     38   virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
     39       v8::Isolate* isolate) OVERRIDE;
     40 
     41   virtual v8::Handle<v8::Object> GetChildAtIndex(unsigned index);
     42   virtual bool IsRoot() const;
     43   bool IsEqualToObject(const blink::WebAXObject& object);
     44 
     45   void NotificationReceived(blink::WebFrame* frame,
     46                             const std::string& notification_name);
     47   void Reset();
     48 
     49  protected:
     50   const blink::WebAXObject& accessibility_object() const {
     51     return accessibility_object_;
     52   }
     53 
     54   Factory* factory() const { return factory_; }
     55 
     56  private:
     57   friend class WebAXObjectProxyBindings;
     58 
     59   // Bound properties.
     60   std::string Role();
     61   std::string Title();
     62   std::string Description();
     63   std::string HelpText();
     64   std::string StringValue();
     65   int X();
     66   int Y();
     67   int Width();
     68   int Height();
     69   int IntValue();
     70   int MinValue();
     71   int MaxValue();
     72   std::string ValueDescription();
     73   int ChildrenCount();
     74   int InsertionPointLineNumber();
     75   std::string SelectedTextRange();
     76   bool IsEnabled();
     77   bool IsRequired();
     78   bool IsFocused();
     79   bool IsFocusable();
     80   bool IsSelected();
     81   bool IsSelectable();
     82   bool IsMultiSelectable();
     83   bool IsSelectedOptionActive();
     84   bool IsExpanded();
     85   bool IsChecked();
     86   bool IsVisible();
     87   bool IsOffScreen();
     88   bool IsCollapsed();
     89   bool HasPopup();
     90   bool IsValid();
     91   bool IsReadOnly();
     92   std::string Orientation();
     93   int ClickPointX();
     94   int ClickPointY();
     95   int32_t RowCount();
     96   int32_t ColumnCount();
     97   bool IsClickable();
     98 
     99   // Bound methods.
    100   std::string AllAttributes();
    101   std::string AttributesOfChildren();
    102   int LineForIndex(int index);
    103   std::string BoundsForRange(int start, int end);
    104   v8::Handle<v8::Object> ChildAtIndex(int index);
    105   v8::Handle<v8::Object> ElementAtPoint(int x, int y);
    106   v8::Handle<v8::Object> TableHeader();
    107   std::string RowIndexRange();
    108   std::string ColumnIndexRange();
    109   v8::Handle<v8::Object> CellForColumnAndRow(int column, int row);
    110   v8::Handle<v8::Object> TitleUIElement();
    111   void SetSelectedTextRange(int selection_start, int length);
    112   bool IsAttributeSettable(const std::string& attribute);
    113   bool IsPressActionSupported();
    114   bool IsIncrementActionSupported();
    115   bool IsDecrementActionSupported();
    116   v8::Handle<v8::Object> ParentElement();
    117   void Increment();
    118   void Decrement();
    119   void ShowMenu();
    120   void Press();
    121   bool IsEqual(v8::Handle<v8::Object> proxy);
    122   void SetNotificationListener(v8::Handle<v8::Function> callback);
    123   void UnsetNotificationListener();
    124   void TakeFocus();
    125   void ScrollToMakeVisible();
    126   void ScrollToMakeVisibleWithSubFocus(int x, int y, int width, int height);
    127   void ScrollToGlobalPoint(int x, int y);
    128   int WordStart(int character_index);
    129   int WordEnd(int character_index);
    130 
    131   blink::WebAXObject accessibility_object_;
    132   Factory* factory_;
    133 
    134   v8::Persistent<v8::Function> notification_callback_;
    135 
    136   DISALLOW_COPY_AND_ASSIGN(WebAXObjectProxy);
    137 };
    138 
    139 class RootWebAXObjectProxy : public WebAXObjectProxy {
    140  public:
    141   RootWebAXObjectProxy(const blink::WebAXObject&, Factory*);
    142 
    143   virtual v8::Handle<v8::Object> GetChildAtIndex(unsigned index) OVERRIDE;
    144   virtual bool IsRoot() const OVERRIDE;
    145 };
    146 
    147 
    148 // Provides simple lifetime management of the WebAXObjectProxy instances: all
    149 // WebAXObjectProxys ever created from the controller are stored in a list and
    150 // cleared explicitly.
    151 class WebAXObjectProxyList : public WebAXObjectProxy::Factory {
    152  public:
    153   WebAXObjectProxyList();
    154   virtual ~WebAXObjectProxyList();
    155 
    156   void Clear();
    157   virtual v8::Handle<v8::Object> GetOrCreate(
    158       const blink::WebAXObject&) OVERRIDE;
    159   v8::Handle<v8::Object> CreateRoot(const blink::WebAXObject&);
    160 
    161  private:
    162   typedef v8::PersistentValueVector<v8::Object> ElementList;
    163   ElementList elements_;
    164 };
    165 
    166 }  // namespace content
    167 
    168 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_AX_OBJECT_PROXY_H_
    169