[ Index ]
 

Code source de Kupu-1.3.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/ -> test_kupuinit.js (source)

   1  /*****************************************************************************
   2   *
   3   * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
   4   *
   5   * This software is distributed under the terms of the Kupu
   6   * License. See LICENSE.txt for license text. For a list of Kupu
   7   * Contributors see CREDITS.txt.
   8   *
   9   *****************************************************************************/
  10  
  11  // $Id: test_kupuinit.js 9982 2005-03-21 09:53:57Z yuppie $
  12  
  13  function InitKupuCheckersTestCase() {
  14      this.name = 'InitKupuCheckersTestCase';
  15      // Please note that we are cheating here a bit:
  16      // 1. No idea how to get the real checkers without setting up a complete
  17      //    Kupu, so we work on a copy here.
  18      // 2. We test parentElement, ParentWithStyleChecker and the arguments
  19      //    used in initKupu simultanously, so these tests don't tell you what's
  20      //    responsible if they fail.
  21  
  22      /*Moz:
  23         <span style="font-weight: bold;">foo</span>
  24         <span style="font-style: italic;">bar</span>
  25         <span style="text-decoration: underline;">baz</span>
  26         <sub>spam</sub>
  27         <sup>eggs</sup>
  28        Moz noCSS:
  29         <b>foo</b>
  30         <i>bar</i>
  31         <u>baz</u>
  32         <sub>spam</sub>
  33         <sup>eggs</sup>
  34        IE:
  35         <STRONG>foo</STRONG>
  36         <EM>bar</EM>
  37         <U>baz</U>
  38         <SUB>spam</SUB>
  39         <SUP>eggs</SUP>*/
  40  
  41      SelectionTestCase.apply(this);
  42      this.base_setUp = this.setUp;
  43  
  44      this._makeBoldchecker = function() {
  45          // XXX copied from initKupu, must be synced manually!
  46          var boldchecker = ParentWithStyleChecker(new Array('b', 'strong'),
  47                                                   'fontWeight', 'bold', 'bold');
  48          return boldchecker;
  49          };
  50  
  51      this._makeItalicschecker = function() {
  52          // XXX copied from initKupu, must be synced manually!
  53          var italicschecker = ParentWithStyleChecker(new Array('i', 'em'),
  54                                                'fontStyle', 'italic', 'italic');
  55          return italicschecker;
  56          };
  57  
  58      this._makeUnderlinechecker = function() {
  59          // XXX copied from initKupu, must be synced manually!
  60          var underlinechecker = ParentWithStyleChecker(new Array('u'),
  61                                     'textDecoration', 'underline', 'underline');
  62          return underlinechecker;
  63          };
  64  
  65      this.setUp = function() {
  66          this.base_setUp();
  67          this.editor = new KupuEditor(this.kupudoc, {}, null);
  68      };
  69  
  70      this.testBoldcheckerBold = function() {
  71          this.body.innerHTML = '<p>foo <b>bar</b></p>';
  72          // select                        |ar|
  73          this._setSelection(5, null, 7, false, 'ar');
  74          var selNode = this.selection.parentElement();
  75          var boldchecker = this._makeBoldchecker();
  76          this.assertEquals(boldchecker(selNode, null, this.editor), true);
  77      };
  78  
  79      this.testBoldcheckerMixed = function() {
  80          this.body.innerHTML = '<p>foo <b>bar</b></p>';
  81          // select                  |o <b>bar|
  82          this._setSelection(2, null, 7, false, 'o bar');
  83          var selNode = this.selection.parentElement();
  84          var boldchecker = this._makeBoldchecker();
  85          this.assertEquals(boldchecker(selNode, null, this.editor), false);
  86      };
  87  
  88      this.testBoldcheckerBoldLeftOuter = function() {
  89          this.body.innerHTML = '<p>foo <b>bar</b></p>';
  90          // select                    |<b>bar|
  91          this._setSelection(4, false, 7, false, 'bar');
  92          var selNode = this.selection.parentElement();
  93          var boldchecker = this._makeBoldchecker();
  94          this.assertEquals(boldchecker(selNode, null, this.editor), true);
  95      };
  96  
  97      this.testBoldcheckerBoldInner = function() {
  98          this.body.innerHTML = '<p>foo <b>bar</b></p>';
  99          // select                       |bar|
 100          this._setSelection(4, true, 7, false, 'bar');
 101          var selNode = this.selection.parentElement();
 102          var boldchecker = this._makeBoldchecker();
 103          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 104      };
 105  
 106      this.testBoldcheckerExecCommand = function() {
 107          this.body.innerHTML = '<p>foo bar</p>';
 108          // select                    |bar|
 109          this._setSelection(4, true, 7, false, 'bar');
 110          this.doc.execCommand('bold', null, null);
 111          var selNode = this.selection.parentElement();
 112          var boldchecker = this._makeBoldchecker();
 113          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 114      };
 115  
 116      this.testBoldcheckerExecCommandCollapsed = function() {
 117          // XXX: the feature seems to work, but test is broken on IE
 118          if (_SARISSA_IS_IE) return;
 119          this.body.innerHTML = '<p>foo bar</p>';
 120          // select                   ||
 121          this._setSelection(3, null, 3, null, '');
 122          this.doc.execCommand('bold', null, null);
 123          var selNode = this.selection.parentElement();
 124          var boldchecker = this._makeBoldchecker();
 125          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 126      };
 127  
 128      this.testBoldcheckerExecCommandNoCSS = function() {
 129          if (_SARISSA_IS_IE) return;
 130          this.doc.execCommand('useCSS', null, true);
 131  
 132          this.body.innerHTML = '<p>foo bar</p>';
 133          // select                    |bar|
 134          this._setSelection(4, null, 7, false, 'bar');
 135          this.doc.execCommand('bold', null, null);
 136          var selNode = this.selection.parentElement();
 137          var boldchecker = this._makeBoldchecker();
 138          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 139  
 140          this.doc.execCommand('useCSS', null, false);
 141      };
 142  
 143      this.testBoldcheckerStrong = function() {
 144          this.body.innerHTML = '<p>foo <strong>bar</strong></p>';
 145          // select                             |ar|
 146          this._setSelection(5, null, 7, false, 'ar');
 147          var selNode = this.selection.parentElement();
 148          var boldchecker = this._makeBoldchecker();
 149          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 150      };
 151  
 152      this.testBoldcheckerStyle = function() {
 153          this.body.innerHTML =
 154                        '<p>foo <span style="font-weight: bold;">bar</span></p>';
 155          // select                                              |ar|
 156          this._setSelection(5, null, 7, false, 'ar');
 157          var selNode = this.selection.parentElement();
 158          var boldchecker = this._makeBoldchecker();
 159          this.assertEquals(boldchecker(selNode, null, this.editor), true);
 160      };
 161  
 162      this.testItalicscheckerItalics = function() {
 163          this.body.innerHTML = '<p>foo <i>bar</i></p>';
 164          // select                        |ar|
 165          this._setSelection(5, null, 7, false, 'ar');
 166          var selNode = this.selection.parentElement();
 167          var italicschecker = this._makeItalicschecker();
 168          this.assertEquals(italicschecker(selNode, null, this.editor), true);
 169      };
 170  
 171      this.testItalicscheckerEmphasis = function() {
 172          this.body.innerHTML = '<p>foo <em>bar</em></p>';
 173          // select                         |ar|
 174          this._setSelection(5, null, 7, false, 'ar');
 175          var selNode = this.selection.parentElement();
 176          var italicschecker = this._makeItalicschecker();
 177          this.assertEquals(italicschecker(selNode, null, this.editor), true);
 178      };
 179  
 180      this.testItalicscheckerStyle = function() {
 181          this.body.innerHTML =
 182                       '<p>foo <span style="font-style: italic;">bar</span></p>';
 183          // select                                              |ar|
 184          this._setSelection(5, null, 7, false, 'ar');
 185          var selNode = this.selection.parentElement();
 186          var italicschecker = this._makeItalicschecker();
 187          this.assertEquals(italicschecker(selNode, null, this.editor), true);
 188      };
 189  
 190      this.testUnderlinecheckerStyle = function() {
 191          this.body.innerHTML =
 192               '<p>foo <span style="text-decoration: underline;">bar</span></p>';
 193          // select                                              |ar|
 194          this._setSelection(5, null, 7, false, 'ar');
 195          var selNode = this.selection.parentElement();
 196          var underlinechecker = this._makeUnderlinechecker();
 197          this.assertEquals(underlinechecker(selNode, null, this.editor), true);
 198      };
 199  };
 200  
 201  InitKupuCheckersTestCase.prototype = new SelectionTestCase;


Généré le : Sun Feb 25 15:30:41 2007 par Balluche grâce à PHPXref 0.7