Пример #1
0
  def testFoldWhitespace(self):
    text = '<td>   Test     Message   </td>'

    html = tr_html.TrHtml(StringIO.StringIO(text))
    html.Parse()
    self.failUnlessEqual(html.skeleton_[1].GetMessage().GetPresentableContent(),
                         'Test  Message')

    html = tr_html.TrHtml(StringIO.StringIO(text))
    html.fold_whitespace_ = True
    html.Parse()
    self.failUnlessEqual(html.skeleton_[1].GetMessage().GetPresentableContent(),
                         'Test Message')
Пример #2
0
  def testExplicitDescriptions(self):
    html = tr_html.TrHtml('Hello [USER]<br/><!-- desc=explicit -->'
                          '<input type="button">Go!</input>')
    html.Parse()
    msg = html.GetCliques()[1].GetMessage()
    self.failUnlessEqual(msg.GetDescription(), 'explicit')
    self.failUnlessEqual(msg.GetRealContent(), 'Go!')

    html = tr_html.TrHtml('Hello [USER]<br/><!-- desc=explicit\nmultiline -->'
                          '<input type="button">Go!</input>')
    html.Parse()
    msg = html.GetCliques()[1].GetMessage()
    self.failUnlessEqual(msg.GetDescription(), 'explicit multiline')
    self.failUnlessEqual(msg.GetRealContent(), 'Go!')
Пример #3
0
 def testRegressionCpuHang(self):
     # If this regression occurs, the unit test will never return
     html = tr_html.TrHtml(
         StringIO(
             '''<input type=text size=12 id=advFileTypeEntry [~SHOW-FILETYPE-BOX~] value="[EXT]" name=ext>'''
         ))
     html.Parse()
Пример #4
0
 def testWhitespaceAfterInlineTag(self):
   '''Test that even if there is whitespace after an inline tag at the start
   of a translateable section the inline tag will be included.
   '''
   html = tr_html.TrHtml('''<label for=DISPLAYNONE><font size=-1> Hello</font>''')
   html.Parse()
   self.failUnless(html.skeleton_[1].GetMessage().GetRealContent() ==
                   '<font size=-1> Hello</font>')
Пример #5
0
  def testSubmitAttribute(self):
    html = tr_html.TrHtml('''</td>
<td class="header-element"><input type=submit value="Save Preferences"
name=submit2></td>
</tr></table>''')
    html.Parse()
    self.failUnless(html.skeleton_[1].GetMessage().GetPresentableContent() ==
                    'Save Preferences')
Пример #6
0
 def testRegressionInToolbarAbout(self):
   html = tr_html.TrHtml(util.PathFromRoot(r'grit/testdata/toolbar_about.html'))
   html.Parse()
   cliques = html.GetCliques()
   for cl in cliques:
     content = cl.GetMessage().GetRealContent()
     if content.count('De parvis grandis acervus erit'):
       self.failIf(content.count('$/translate'))
Пример #7
0
 def testSetAttributes(self):
     html = tr_html.TrHtml(StringIO(''))
     self.failUnlessEqual(html.fold_whitespace_, False)
     html.SetAttributes({})
     self.failUnlessEqual(html.fold_whitespace_, False)
     html.SetAttributes({'fold_whitespace': 'false'})
     self.failUnlessEqual(html.fold_whitespace_, False)
     html.SetAttributes({'fold_whitespace': 'true'})
     self.failUnlessEqual(html.fold_whitespace_, True)
Пример #8
0
  def testTable(self):
    html = tr_html.TrHtml('''<table class="shaded-header"><tr>
<td class="header-element b expand">Preferences</td>
<td class="header-element s">
<a href="http://desktop.google.com/preferences.html">Preferences&nbsp;Help</a>
</td>
</tr></table>''')
    html.Parse()
    self.failUnless(html.skeleton_[3].GetMessage().GetPresentableContent() ==
                    'BEGIN_LINKPreferences&nbsp;HelpEND_LINK')
Пример #9
0
    def HtmlFromFileWithManualCheck(self, f):
        html = tr_html.TrHtml(f)
        html.Parse()

        # For manual results inspection only...
        list = []
        for item in html.skeleton_:
            if isinstance(item, six.string_types):
                list.append(item)
            else:
                list.append(item.GetMessage().GetPresentableContent())

        return html
Пример #10
0
  def testSillyHeader(self):
    html = tr_html.TrHtml('''[!]
title\tHello
bingo
bongo
bla

<p>Other stuff</p>''')
    html.Parse()
    content = html.skeleton_[1].GetMessage().GetRealContent()
    self.failUnless(content == 'Hello')
    self.failUnless(html.skeleton_[-1] == '</p>')
    # Right after the translateable the nontranslateable should start with
    # a linebreak (this catches a bug we had).
    self.failUnless(html.skeleton_[2][0] == '\n')
Пример #11
0
 def testTranslate(self):
     # Note that the English translation of documents that use character
     # literals (e.g. &copy;) will not be the same as the original document
     # because the character literal will be transformed into the Unicode
     # character itself.  So for this test we choose some relatively complex
     # HTML without character entities (but with &nbsp; because that's handled
     # specially).
     html = tr_html.TrHtml(
         StringIO('''  <script>
   <!--
   function checkOffice() { var w = document.getElementById("h7");
   var e = document.getElementById("h8"); var o = document.getElementById("h10");
   if (!(w.checked || e.checked)) { o.checked=0;o.disabled=1;} else {o.disabled=0;} }
   // -->
     </script>
     <input type=checkbox [CHECK-DOC] name=DOC id=h7 onclick='checkOffice()'>
     <label for=h7> Word</label><br>
     <input type=checkbox [CHECK-XLS] name=XLS id=h8 onclick='checkOffice()'>
     <label for=h8> Excel</label><br>
     <input type=checkbox [CHECK-PPT] name=PPT id=h9>
     <label for=h9> PowerPoint</label><br>
     </span></td><td nowrap valign=top><span class="s">
     <input type=checkbox [CHECK-PDF] name=PDF id=hpdf>
     <label for=hpdf> PDF</label><br>
     <input type=checkbox [CHECK-TXT] name=TXT id=h6>
     <label for=h6> Text, media, and other files</label><br>
    </tr>&nbsp;&nbsp;
    <tr><td nowrap valign=top colspan=3><span class="s"><br />
    <input type=checkbox [CHECK-SECUREOFFICE] name=SECUREOFFICE id=h10>
     <label for=h10> Password-protected Office documents (Word, Excel)</label><br />
     <input type=checkbox [DISABLED-HTTPS] [CHECK-HTTPS] name=HTTPS id=h12><label
     for=h12> Secure pages (HTTPS) in web history</label></span></td></tr>
   </table>'''))
     html.Parse()
     trans = html.Translate('en')
     if (html.GetText() != trans):
         self.fail()